public function validate_status_update($new_status, $form)
 {
     $note = rgpost('gravityflow_note');
     $valid = true;
     switch ($this->note_mode) {
         case 'required':
             $valid = !empty($note);
             break;
         case 'required_if_in_progress':
             if ($new_status == 'in_progress' && empty($note)) {
                 $valid = false;
             }
             break;
         case 'required_if_complete':
             if ($new_status == 'complete' && empty($note)) {
                 $valid = false;
             }
     }
     if (!$valid) {
         $form['workflow_note'] = array('failed_validation' => true, 'validation_message' => esc_html__('A note is required'));
     }
     $editable_fields = $this->get_editable_fields();
     foreach ($form['fields'] as $field) {
         /* @var GF_Field $field */
         if (in_array($field->id, $editable_fields)) {
             $value = GFFormsModel::get_field_value($field);
             if ($field->get_input_type() == 'fileupload') {
                 $entry = $this->get_entry();
                 $input_name = 'input_' . $field->id;
                 $form_id = $form['id'];
                 $value = null;
                 if (isset($entry[$field->id])) {
                     $value = $entry[$field->id];
                 }
                 if (!empty($_FILES[$input_name]) && !empty($_FILES[$input_name]['name'])) {
                     $file_path = GFFormsModel::get_file_upload_path($form['id'], $_FILES[$input_name]['name']);
                     $value = $file_path['url'];
                 } else {
                     $_FILES[$input_name] = array('name' => '', 'size' => '');
                 }
                 if ($field->multipleFiles) {
                     if (isset(GFFormsModel::$uploaded_files[$form_id][$input_name])) {
                         $value = empty($value) ? '[]' : $value;
                         $value = stripslashes_deep($value);
                         $value = GFFormsModel::prepare_value($form, $field, $value, $input_name, $entry['id'], array());
                     }
                 } else {
                     GFFormsModel::$uploaded_files[$form_id][$input_name] = $value;
                 }
                 $original_value = GFFormsModel::get_lead_field_value($entry, $field);
                 if (empty($value) && !empty($original_value)) {
                     continue;
                 }
                 $_POST[$input_name] = $value;
                 if ($field->isRequired && empty($value)) {
                     $field->failed_validation = true;
                     $field->validation_message = empty($field->errorMessage) ? __('This field is required.', 'gravityforms') : $field->errorMessage;
                     $valid = false;
                 }
                 $field->validate($value, $form);
                 if ($field->failed_validation) {
                     $valid = false;
                 }
                 continue;
             }
             if ($field->isRequired && $field->is_value_submission_empty($form['id'])) {
                 $field->failed_validation = true;
                 $field->validation_message = empty($field->errorMessage) ? __('This field is required.', 'gravityforms') : $field->errorMessage;
                 $valid = false;
             } else {
                 $field->validate($value, $form);
                 if ($field->failed_validation) {
                     $valid = false;
                 }
             }
         }
     }
     $validation_result = array('is_valid' => $valid, 'form' => $form);
     $validation_result = apply_filters('gravityflow_validation_user_input', $validation_result, $this);
     if (!is_wp_error($validation_result)) {
         if (!$validation_result['is_valid']) {
             $valid = new WP_Error('validation_result', esc_html__('There was a problem while updating your form.', 'gravityflow'), $validation_result);
         }
     }
     return $valid;
 }
 /**
  * Add field keys that Gravity Forms expects.
  *
  * @see GFFormDisplay::validate()
  * @param  array $form GF Form
  * @return array       Modified GF Form
  */
 function gform_pre_validation($form)
 {
     if (!$this->verify_nonce()) {
         return $form;
     }
     // Fix PHP warning regarding undefined index.
     foreach ($form['fields'] as &$field) {
         // This is because we're doing admin form pretending to be front-end, so Gravity Forms
         // expects certain field array items to be set.
         foreach (array('noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions') as $key) {
             $field->{$key} = isset($field->{$key}) ? $field->{$key} : NULL;
         }
         // unset emailConfirmEnabled for email type fields
         /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) {
                $field['emailConfirmEnabled'] = '';
            }*/
         switch (RGFormsModel::get_input_type($field)) {
             /**
              * this whole fileupload hack is because in the admin, Gravity Forms simply doesn't update any fileupload field if it's empty, but it DOES in the frontend.
              *
              * What we have to do is set the value so that it doesn't get overwritten as empty on save and appears immediately in the Edit Entry screen again.
              *
              * @hack
              */
             case 'fileupload':
             case 'post_image':
                 // Set the previous value
                 $entry = $this->get_entry();
                 $input_name = 'input_' . $field->id;
                 $form_id = $form['id'];
                 $value = NULL;
                 // Use the previous entry value as the default.
                 if (isset($entry[$field->id])) {
                     $value = $entry[$field->id];
                 }
                 // If this is a single upload file
                 if (!empty($_FILES[$input_name]) && !empty($_FILES[$input_name]['name'])) {
                     $file_path = GFFormsModel::get_file_upload_path($form['id'], $_FILES[$input_name]['name']);
                     $value = $file_path['url'];
                 } else {
                     // Fix PHP warning on line 1498 of form_display.php for post_image fields
                     // Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
                     $_FILES[$input_name] = array('name' => '', 'size' => '');
                 }
                 if (rgar($field, "multipleFiles")) {
                     // If there are fresh uploads, process and merge them.
                     // Otherwise, use the passed values, which should be json-encoded array of URLs
                     if (isset(GFFormsModel::$uploaded_files[$form_id][$input_name])) {
                         $value = empty($value) ? '[]' : $value;
                         $value = stripslashes_deep($value);
                         $value = GFFormsModel::prepare_value($form, $field, $value, $input_name, $entry['id'], array());
                     }
                 } else {
                     // A file already exists when editing an entry
                     // We set this to solve issue when file upload fields are required.
                     GFFormsModel::$uploaded_files[$form_id][$input_name] = $value;
                 }
                 $_POST[$input_name] = $value;
                 break;
             case 'number':
                 // Fix "undefined index" issue at line 1286 in form_display.php
                 if (!isset($_POST['input_' . $field->id])) {
                     $_POST['input_' . $field->id] = NULL;
                 }
                 break;
             case 'captcha':
                 // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php
                 $_POST['recaptcha_challenge_field'] = NULL;
                 $_POST['recaptcha_response_field'] = NULL;
                 break;
         }
     }
     return $form;
 }
Esempio n. 3
0
 public function get_limit_field_values($form_id, $field_ids)
 {
     $form = GFAPI::get_form($form_id);
     $values = array();
     foreach ($field_ids as $field_id) {
         $field = GFFormsModel::get_field($form, $field_id);
         $input_name = 'input_' . str_replace('.', '_', $field_id);
         $value = GFFormsModel::prepare_value($form, $field, rgpost($input_name), $input_name, null);
         if (!rgblank($value)) {
             $values[$field_id] = $value;
         }
     }
     return $values;
 }