Exemplo n.º 1
0
 function saveForm($params)
 {
     $objForm = new FormModel();
     $objSettings = Settings::getInstance();
     $defaultEmail = $objSettings->getEntry('admin', 'admin-email');
     $saveData = array();
     $saveData['id'] = !empty($params['form_id']) ? intval($params['form_id']) : false;
     $saveData['name'] = !empty($params['form_name']) ? $params['form_name'] : 'Unnamed';
     $saveData['emailTo'] = !empty($params['form_emailto']) ? $params['form_emailto'] : $defaultEmail;
     $saveData['captcha'] = !empty($params['form_captcha']) ? 1 : 0;
     $saveData['thanksmsg'] = !empty($params['form_thanksmsg']) ? $params['form_thanksmsg'] : 'Thanks';
     $saveData['emailSubject'] = !empty($params['form_emailsubject']) ? $params['form_emailsubject'] : 'Form Submitted';
     $saveData['emailFrom'] = !empty($params['form_emailfrom']) ? $params['form_emailfrom'] : $defaultEmail;
     $saveData['keyName'] = !empty($params['form_keyname']) ? $params['form_keyname'] : false;
     if (!empty($params['form_new_fields'])) {
         foreach ($params['form_new_fields']['name'] as $pointer => $ignore) {
             if (!empty($params['form_new_fields']['name'][$pointer])) {
                 $newField = array();
                 $newField['name'] = !empty($params['form_new_fields']['name'][$pointer]) ? $params['form_new_fields']['name'][$pointer] : false;
                 $newField['type'] = !empty($params['form_new_fields']['type'][$pointer]) ? $params['form_new_fields']['type'][$pointer] : false;
                 $newField['field_name'] = !empty($params['form_new_fields']['field_name'][$pointer]) ? $params['form_new_fields']['field_name'][$pointer] : false;
                 $newField['value'] = !empty($params['form_new_fields']['value'][$pointer]) ? $params['form_new_fields']['value'][$pointer] : false;
                 $newField['values'] = !empty($params['form_new_fields']['values'][$pointer]) ? $params['form_new_fields']['values'][$pointer] : false;
                 $newField['width'] = !empty($params['form_new_fields']['width'][$pointer]) ? $params['form_new_fields']['width'][$pointer] : false;
                 $newField['height'] = !empty($params['form_new_fields']['height'][$pointer]) ? $params['form_new_fields']['height'][$pointer] : false;
                 $newField['required'] = !empty($params['form_new_fields']['required'][$pointer]) ? $params['form_new_fields']['required'][$pointer] : false;
                 $newField['validateAs'] = !empty($params['form_new_fields']['validateas'][$pointer]) ? $params['form_new_fields']['validateas'][$pointer] : false;
                 $params['form_fields'][] = $newField;
             } else {
                 // skip
             }
         }
     }
     if (!empty($params['form_fields'])) {
         foreach ($params['form_fields'] as $field) {
             $fieldSaveData = array();
             $fieldSaveData['id'] = !empty($field['id']) ? intval($field['id']) : false;
             $fieldSaveData['name'] = !empty($field['name']) ? $field['name'] : 'Unnamed';
             $fieldSaveData['type'] = !empty($field['type']) ? $field['type'] : 'text';
             $fieldSaveData['values'] = !empty($field['values']) ? $field['values'] : false;
             $fieldSaveData['width'] = !empty($field['width']) ? $field['width'] : false;
             $fieldSaveData['height'] = !empty($field['height']) ? $field['height'] : false;
             $fieldSaveData['required'] = !empty($field['required']) ? 1 : 0;
             $fieldSaveData['validateAs'] = !empty($field['validateas']) ? $field['validateas'] : false;
             $fieldSaveData['value'] = !empty($field['value']) ? $field['value'] : false;
             $fieldSaveData['field_name'] = !empty($field['field_name']) ? $field['field_name'] : false;
             $saveData['fields'][] = $fieldSaveData;
         }
     }
     $form_id = $objForm->saveForm($saveData);
     return $form_id;
 }