Esempio n. 1
0
 public static function get_field($field, $value = '', $force_frontend_label = false, $form = null, $field_values = null)
 {
     $is_form_editor = GFCommon::is_form_editor();
     $is_entry_detail = GFCommon::is_entry_detail();
     $is_admin = $is_form_editor || $is_entry_detail;
     $custom_class = $is_admin ? '' : $field->cssClass;
     if ($field->type == 'page') {
         if ($is_entry_detail) {
             return;
             //ignore page breaks in the entry detail page
         } else {
             if (!$is_form_editor) {
                 $save_button = rgars($form, 'save/enabled') ? self::get_form_button($form['id'], "gform_save_{$form['id']}", $form['save']['button'], rgars($form, 'save/button/text'), 'gform_save_link', rgars($form, 'save/button/text'), 0, "jQuery(\"#gform_save_{$form['id']}\").val(1);") : '';
                 $next_button = rgobj($field, 'nextButton') && !is_array($field->nextButton) ? $field->nextButton : self::get_form_button($form['id'], "gform_next_button_{$form['id']}_{$field->id}", $field->nextButton, __('Next', 'gravityforms'), 'gform_next_button', __('Next Page', 'gravityforms'), $field->pageNumber);
                 $next_button = gf_apply_filters('gform_next_button', $form['id'], $next_button, $form);
                 $previous_button = $field->pageNumber == 2 ? '' : self::get_form_button($form['id'], "gform_previous_button_{$form['id']}_{$field->id}", $field->previousButton, __('Previous', 'gravityforms'), 'gform_previous_button', __('Previous Page', 'gravityforms'), $field->pageNumber - 2);
                 if (!empty($previous_button)) {
                     $previous_button = gf_apply_filters('gform_previous_button', $form['id'], $previous_button, $form);
                 }
                 $style = self::is_page_active($form['id'], $field->pageNumber) ? '' : "style='display:none;'";
                 $custom_class = !empty($custom_class) ? " {$custom_class}" : '';
                 $html = "</ul>\n                    </div>\n                    <div class='gform_page_footer'>\n                        {$previous_button} {$next_button} {$save_button}\n                    </div>\n                </div>\n                <div id='gform_page_{$form['id']}_{$field->pageNumber}' class='gform_page{$custom_class}' {$style}>\n                    <div class='gform_page_fields'>\n                        <ul id='gform_fields_{$form['id']}_{$field->pageNumber}' class='" . GFCommon::get_ul_classes($form) . "'>";
                 return $html;
             }
         }
     }
     if (!$is_admin && $field->adminOnly) {
         if ($field->allowsPrepopulate) {
             $field->inputType = 'adminonly_hidden';
         } else {
             return;
         }
     }
     $id = $field->id;
     $input_type = GFFormsModel::get_input_type($field);
     $error_class = $field->failed_validation ? 'gfield_error' : '';
     $admin_only_class = $field->adminOnly ? 'field_admin_only' : '';
     $selectable_class = $is_admin ? 'selectable' : '';
     $hidden_class = in_array($input_type, array('hidden', 'hiddenproduct')) ? 'gform_hidden' : '';
     $section_class = $field->type == 'section' ? 'gsection' : '';
     $page_class = $field->type == 'page' ? 'gpage' : '';
     $html_block_class = $field->type == 'html' ? 'gfield_html' : '';
     $html_formatted_class = $field->type == 'html' && !$is_admin && !$field->disableMargins ? 'gfield_html_formatted' : '';
     $html_no_follows_desc_class = $field->type == 'html' && !$is_admin && !self::prev_field_has_description($form, $field->id) ? 'gfield_no_follows_desc' : '';
     $calculation_class = $input_type == 'calculation' || $input_type == 'number' && $field->has_calculation() ? 'gfield_calculation' : '';
     $product_suffix = "_{$form['id']}_" . $field->productField;
     $option_class = $field->type == 'option' ? "gfield_price gfield_price{$product_suffix} gfield_option{$product_suffix}" : '';
     $quantity_class = $field->type == 'quantity' ? "gfield_price gfield_price{$product_suffix} gfield_quantity gfield_quantity{$product_suffix}" : '';
     $total_class = $field->type == 'total' ? "gfield_price gfield_price{$product_suffix} gfield_total gfield_total{$product_suffix}" : '';
     $shipping_class = $field->type == 'shipping' ? "gfield_price gfield_shipping gfield_shipping_{$form['id']}" : '';
     $product_class = $field->type == 'product' ? "gfield_price gfield_price_{$form['id']}_{$field->id} gfield_product_{$form['id']}_{$field->id}" : '';
     $hidden_product_class = $input_type == 'hiddenproduct' ? 'gfield_hidden_product' : '';
     $donation_class = $field->type == 'donation' ? "gfield_price gfield_price_{$form['id']}_{$field->id} gfield_donation_{$form['id']}_{$field->id}" : '';
     $required_class = $field->isRequired ? 'gfield_contains_required' : '';
     $creditcard_warning_class = $input_type == 'creditcard' && !GFCommon::is_ssl() ? 'gfield_creditcard_warning' : '';
     $form_sublabel_setting = rgempty('subLabelPlacement', $form) ? 'below' : $form['subLabelPlacement'];
     $sublabel_setting = !isset($field->subLabelPlacement) || empty($field->subLabelPlacement) ? $form_sublabel_setting : $field->subLabelPlacement;
     $sublabel_class = "field_sublabel_{$sublabel_setting}";
     $form_description_setting = rgempty('descriptionPlacement', $form) ? 'below' : $form['descriptionPlacement'];
     $description_setting = !isset($field->descriptionPlacement) || empty($field->descriptionPlacement) ? $form_description_setting : $field->descriptionPlacement;
     $description_class = "field_description_{$description_setting}";
     $field_setting_label_placement = $field->labelPlacement;
     $label_placement = empty($field_setting_label_placement) ? '' : $field_setting_label_placement;
     $css_class = "{$selectable_class} gfield {$error_class} {$section_class} {$admin_only_class} {$custom_class} {$hidden_class} {$html_block_class} {$html_formatted_class} {$html_no_follows_desc_class} {$option_class} {$quantity_class} {$product_class} {$total_class} {$donation_class} {$shipping_class} {$page_class} {$required_class} {$hidden_product_class} {$creditcard_warning_class} {$calculation_class} {$sublabel_class} {$description_class} {$label_placement}";
     $css_class = preg_replace('/\\s+/', ' ', $css_class);
     //removing extra spaces
     $css_class = gf_apply_filters('gform_field_css_class', $form['id'], trim($css_class), $field, $form);
     $style = '';
     $field_id = $is_admin || empty($form) ? "field_{$id}" : 'field_' . $form['id'] . "_{$id}";
     $field_content = self::get_field_content($field, $value, $force_frontend_label, $form == null ? 0 : $form['id'], $form);
     $field_container = "<li id='{$field_id}' class='{$css_class}' {$style}>{FIELD_CONTENT}</li>";
     $field_container = gf_apply_filters('gform_field_container', array($form['id'], $field->id), $field_container, $field, $form, $css_class, $style, $field_content);
     $field_markup = str_replace('{FIELD_CONTENT}', $field_content, $field_container);
     return $field_markup;
 }
 public static function has_currency_value($field)
 {
     $has_currency = self::is_pricing_field($field->type) || rgobj($field, 'numberFormat') == 'currency';
     return $has_currency;
 }
 /**
  * Make validation work for Edit Entry
  *
  * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
  * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
  * fields. This goes through all the fields and if they're an invalid post field, we
  * set them as valid. If there are still issues, we'll return false.
  *
  * @param  [type] $validation_results [description]
  * @return [type]                     [description]
  */
 function custom_validation($validation_results)
 {
     do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results);
     do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html(print_r($_POST, true)));
     $gv_valid = true;
     foreach ($validation_results['form']['fields'] as $key => &$field) {
         $value = RGFormsModel::get_field_value($field);
         $field_type = RGFormsModel::get_input_type($field);
         // Validate always
         switch ($field_type) {
             case 'fileupload':
             case 'post_image':
                 // in case nothing is uploaded but there are already files saved
                 if (!empty($field->failed_validation) && !empty($field->isRequired) && !empty($value)) {
                     $field->failed_validation = false;
                     unset($field->validation_message);
                 }
                 // validate if multi file upload reached max number of files [maxFiles] => 2
                 if (rgobj($field, 'maxFiles') && rgobj($field, 'multipleFiles')) {
                     $input_name = 'input_' . $field->id;
                     //uploaded
                     $file_names = isset(GFFormsModel::$uploaded_files[$validation_results['form']['id']][$input_name]) ? GFFormsModel::$uploaded_files[$validation_results['form']['id']][$input_name] : array();
                     //existent
                     $entry = $this->get_entry();
                     $value = NULL;
                     if (isset($entry[$field->id])) {
                         $value = json_decode($entry[$field->id], true);
                     }
                     // count uploaded files and existent entry files
                     $count_files = count($file_names) + count($value);
                     if ($count_files > $field->maxFiles) {
                         $field->validation_message = __('Maximum number of files reached', 'gravityview');
                         $field->failed_validation = 1;
                         $gv_valid = false;
                         // in case of error make sure the newest upload files are removed from the upload input
                         GFFormsModel::$uploaded_files[$validation_results['form']['id']] = null;
                     }
                 }
                 break;
         }
         // This field has failed validation.
         if (!empty($field->failed_validation)) {
             do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array('field' => $field, 'value' => $value));
             switch ($field_type) {
                 // Captchas don't need to be re-entered.
                 case 'captcha':
                     // Post Image fields aren't editable, so we un-fail them.
                 // Post Image fields aren't editable, so we un-fail them.
                 case 'post_image':
                     $field->failed_validation = false;
                     unset($field->validation_message);
                     break;
             }
             // You can't continue inside a switch, so we do it after.
             if (empty($field->failed_validation)) {
                 continue;
             }
             // checks if the No Duplicates option is not validating entry against itself, since
             // we're editing a stored entry, it would also assume it's a duplicate.
             if (!empty($field->noDuplicates)) {
                 $entry = $this->get_entry();
                 // If the value of the entry is the same as the stored value
                 // Then we can assume it's not a duplicate, it's the same.
                 if (!empty($entry) && $value == $entry[$field->id]) {
                     //if value submitted was not changed, then don't validate
                     $field->failed_validation = false;
                     unset($field->validation_message);
                     do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry);
                     continue;
                 }
             }
             // if here then probably we are facing the validation 'At least one field must be filled out'
             if (GFFormDisplay::is_empty($field, $this->form_id) && empty($field->isRequired)) {
                 unset($field->validation_message);
                 $field->validation_message = false;
                 continue;
             }
             $gv_valid = false;
         }
     }
     $validation_results['is_valid'] = $gv_valid;
     do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results);
     // We'll need this result when rendering the form ( on GFFormDisplay::get_form )
     $this->form_after_validation = $validation_results['form'];
     return $validation_results;
 }