/** * Construct and intialize custom Gravity Forms fields. */ public function __construct() { // Enable credit card field add_filter('gform_enable_credit_card_field', '__return_true'); // Register custom fields if (Pronamic_WP_Pay_Class::method_exists('GF_Fields', 'register')) { GF_Fields::register(new Pronamic_WP_Pay_Extensions_GravityForms_PaymentMethodsField()); GF_Fields::register(new Pronamic_WP_Pay_Extensions_GravityForms_IssuersField()); } // Add extra fields settings add_action('gform_field_standard_settings', array($this, 'field_standard_settings'), 10, 2); }
/** * Hook some stuffs! */ static function init() { add_filter('gform_add_field_buttons', [__CLASS__, 'add_field_buttons']); add_filter('gform_field_type_title', [__CLASS__, 'field_title']); add_filter('gform_field_input', [__CLASS__, 'field'], 10, 5); add_action('gform_field_standard_settings', [__CLASS__, 'settings'], 10, 2); add_action('gform_editor_js_set_default_values', [__CLASS__, 'field_edit_defaults']); add_action('gform_editor_js', [__CLASS__, 'editor_js']); add_action('gform_enqueue_scripts', [__CLASS__, 'enqueue_scripts'], 10, 2); add_action('gform_after_submission', [__CLASS__, 'after_submission'], 1, 2); add_filter('gform_save_field_value', [__CLASS__, 'save_field_value'], 10, 5); add_action('gform_update_post/setup_form', [__CLASS__, 'capture_post_id']); add_action('gform_loaded', function () { require __DIR__ . '/TermSelectField.php'; \GF_Fields::register(new TermSelectField()); }); }
public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead) { return empty($value) ? '' : is_array($value) ? implode(',', $value) : $value; } public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format) { if ($this->type == 'post_category') { $use_id = $modifier == 'id'; $items = explode(',', $value); if (is_array($items)) { $cats = array(); foreach ($items as $item) { $cat = GFCommon::format_post_category($item, $use_id); $cats[] = GFCommon::format_variable_value($cat, $url_encode, $esc_html, $format); } $value = GFCommon::implode_non_blank(', ', $cats); } } return $value; } public function sanitize_settings() { parent::sanitize_settings(); $this->enableEnhancedUI = (bool) $this->enableEnhancedUI; if ($this->type === 'post_category') { $this->displayAllCategories = (bool) $this->displayAllCategories; } } } GF_Fields::register(new GF_Field_MultiSelect());
$html_input_type = RGFormsModel::is_html5_enabled() ? 'tel' : 'text'; $logic_event = $this->get_conditional_logic_event('keyup'); $placeholder_attribute = $this->get_field_placeholder_attribute(); $tabindex = $this->get_tabindex(); return sprintf("<div class='ginput_container'><input name='input_%d' id='%s' type='{$html_input_type}' value='%s' class='%s' {$tabindex} {$logic_event} {$placeholder_attribute} %s/>{$instruction_div}</div>", $id, $field_id, esc_attr($value), esc_attr($class), $disabled_text); } public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead) { if ($this->phoneFormat == 'standard' && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) { $value = sprintf('(%s) %s-%s', $matches[1], $matches[2], $matches[3]); } return $value; } public function get_form_inline_script_on_page_render($form) { $script = ''; if ($this->phoneFormat == 'standard') { $script = "if(!/(android)/i.test(navigator.userAgent)){jQuery('#input_{$form['id']}_{$this->id}').mask('(999) 999-9999').bind('keypress', function(e){if(e.which == 13){jQuery(this).blur();} } );}"; } return $script; } public function sanitize_settings() { parent::sanitize_settings(); if ($this->phoneFormat && !in_array($this->phoneFormat, array('standard', 'international'))) { $this->phoneFormat = 'standard'; } } } GF_Fields::register(new GF_Field_Phone());
return "<div class='ginput_complex ginput_container ginput_container_email' id='{$field_id}_container'>\n <span id='{$field_id}_1_container' class='ginput_left'>\n <input class='{$class}' type='{$html_input_type}' name='input_{$id}' id='{$field_id}' value='{$email_value}' {$first_tabindex} {$logic_event} {$disabled_text} {$enter_email_placeholder_attribute} {$required_attribute} {$invalid_attribute}/>\n <label for='{$field_id}' {$sub_label_class_attribute}>{$enter_email_label}</label>\n </span>\n <span id='{$field_id}_2_container' class='ginput_right'>\n <input class='{$class}' type='{$html_input_type}' name='input_{$id}_2' id='{$field_id}_2' value='{$confirmation_value}' {$last_tabindex} {$confirmation_disabled} {$confirm_email_placeholder_attribute} {$required_attribute} {$invalid_attribute}/>\n <label for='{$field_id}_2' {$sub_label_class_attribute}>{$confirm_email_label}</label>\n </span>\n <div class='gf_clear gf_clear_complex'></div>\n </div>"; } } else { $tabindex = $this->get_tabindex(); $value = esc_attr($value); $class = esc_attr($class); return "<div class='ginput_container ginput_container_email'>\n <input name='input_{$id}' id='{$field_id}' type='{$html_input_type}' value='{$value}' class='{$class}' {$tabindex} {$logic_event} {$disabled_text} {$single_placeholder_attribute}/>\n </div>"; } } } public function get_field_label_class() { return $this->emailConfirmEnabled ? 'gfield_label gfield_label_before_complex' : 'gfield_label'; } public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen') { return GFCommon::is_valid_email($value) && $format == 'html' ? "<a href='mailto:{$value}'>{$value}</a>" : $value; } public function get_value_submission($field_values, $get_from_post_global_var = true) { if ($this->emailConfirmEnabled && !$this->is_entry_detail() && is_array($this->inputs)) { $value[0] = $this->get_input_value_submission('input_' . $this->id, $this->inputName, $field_values, $get_from_post_global_var); $value[1] = $this->get_input_value_submission('input_' . $this->id . '_2', $this->inputName, $field_values, $get_from_post_global_var); } else { $value = $this->get_input_value_submission('input_' . $this->id, $this->inputName, $field_values, $get_from_post_global_var); } return $value; } } GF_Fields::register(new GF_Field_Email());
return $value; } public function get_entry_inputs() { return null; } /** * Support for legacy Time fields which did not have an inputs array * * @param $form * * @return string */ public function get_first_input_id($form) { // legacy (< 1.9) Time fields did not have an inputs array if (!is_array($this->inputs)) { return 'input_' . $form['id'] . '_' . $this->id . '_1'; } return parent::get_first_input_id($form); } public function sanitize_settings() { parent::sanitize_settings(); if (!$this->timeFormat || !in_array($this->timeFormat, array(12, 24))) { $this->timeFormat = '12'; } } } GF_Fields::register(new GF_Field_Time());
if ($placeholder !== false) { $str .= "<option value=''>{$placeholder}</option>"; } $increment = $start_number < $end_number ? 1 : -1; for ($i = $start_number; $i != $end_number + $increment; $i += $increment) { $selected = intval($i) == intval($selected_value) ? "selected='selected'" : ''; $str .= "<option value='{$i}' {$selected}>{$i}</option>"; } $str .= '</select>'; return $str; } public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead) { return GFFormsModel::prepare_date($this->dateFormat, $value); } public function get_entry_inputs() { return null; } public function sanitize_settings() { parent::sanitize_settings(); $this->calendarIconType = wp_strip_all_tags($this->calendarIconType); $this->calendarIconUrl = wp_strip_all_tags($this->calendarIconUrl); if ($this->dateFormat && !in_array($this->dateFormat, array('mdy', 'dmy', 'dmy_dash', 'dmy_dot', 'ymd_slash', 'ymd_dash', 'ymd_dot'))) { $this->dateFormat = 'mdy'; } } } GF_Fields::register(new GF_Field_Date());
{ $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $content = $is_entry_detail || $is_form_editor ? "<div class='gf-html-container'><span class='gf_blockheader'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class='fa fa-code fa-lg'></i> " . __('HTML Content', 'gravityforms') . '</span><span>' . __('This is a content placeholder. HTML content is not displayed in the form admin. Preview this form to view the content.', 'gravityforms') . '</span></div>' : $this->content; $content = GFCommon::replace_variables_prepopulate($content); // adding support for merge tags $content = do_shortcode($content); // adding support for shortcodes return $content; } public function get_field_content($value, $force_frontend_label, $form) { $form_id = $form['id']; $admin_buttons = $this->get_admin_buttons(); $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $is_admin = $is_entry_detail || $is_form_editor; $field_label = $this->get_field_label($force_frontend_label, $value); $field_id = $is_admin || $form_id == 0 ? "input_{$this->id}" : 'input_' . $form_id . "_{$this->id}"; $field_content = !$is_admin ? '{FIELD}' : ($field_content = sprintf("%s<label class='gfield_label' for='%s'>%s</label>{FIELD}", $admin_buttons, $field_id, esc_html($field_label))); return $field_content; } public function sanitize_settings() { parent::sanitize_settings(); $allowed_tags = wp_kses_allowed_html('post'); $this->content = wp_kses($this->content, $allowed_tags); } } GF_Fields::register(new GF_Field_HTML());
return true; } public function get_field_input($form, $value = '', $entry = null) { $form_id = absint($form['id']); $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $id = (int) $this->id; $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $value = esc_textarea($value); $size = $this->size; $class_suffix = $is_entry_detail ? '_admin' : ''; $class = $size . $class_suffix; $class = esc_attr($class); $disabled_text = $is_form_editor ? 'disabled="disabled"' : ''; $tabindex = $this->get_tabindex(); $logic_event = $this->get_conditional_logic_event('keyup'); $placeholder_attribute = $this->get_field_placeholder_attribute(); return "<div class='ginput_container ginput_container_post_excerpt'>\r\n\t\t\t\t\t<textarea name='input_{$id}' id='{$field_id}' class='textarea {$class}' {$tabindex} {$logic_event} {$placeholder_attribute} {$disabled_text} rows='10' cols='50'>{$value}</textarea>\r\n\t\t\t\t</div>"; } public function allow_html() { return true; } public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br) { return $format == 'html' && !$nl2br ? nl2br($value) : $value; } } GF_Fields::register(new GF_Field_Post_Excerpt());
<?php if (!class_exists('GFForms')) { die; } class GF_Field_Section extends GF_Field { public $type = 'section'; public function get_form_editor_field_title() { return esc_attr__('Section', 'gravityforms'); } function get_form_editor_field_settings() { return array('conditional_logic_field_setting', 'label_setting', 'description_setting', 'visibility_setting', 'css_class_setting'); } public function get_field_content($value, $force_frontend_label, $form) { $field_label = $this->get_field_label($force_frontend_label, $value); $admin_buttons = $this->get_admin_buttons(); $description = $this->get_description($this->description, 'gsection_description'); $field_content = sprintf("%s<h2 class='gsection_title'>%s</h2>%s", $admin_buttons, esc_html($field_label), $description); return $field_content; } } GF_Fields::register(new GF_Field_Section());
$last = trim(rgget($this->id . '.6', $value)); $suffix = trim(rgget($this->id . '.8', $value)); $name = $prefix; $name .= !empty($name) && !empty($first) ? " {$first}" : $first; $name .= !empty($name) && !empty($middle) ? " {$middle}" : $middle; $name .= !empty($name) && !empty($last) ? " {$last}" : $last; $name .= !empty($name) && !empty($suffix) ? " {$suffix}" : $suffix; return $name; } else { return $value; } } public function get_input_property($input_id, $property_name) { $input = GFFormsModel::get_input($this, $this->id . '.' . (string) $input_id); return rgar($input, $property_name); } public function sanitize_settings() { parent::sanitize_settings(); if (is_array($this->inputs)) { foreach ($this->inputs as &$input) { if (isset($input['choices']) && is_array($input['choices'])) { $input['choices'] = $this->sanitize_settings_choices($input['choices']); } } } } } GF_Fields::register(new GF_Field_Name());
return array('conditional_logic_field_setting', 'prepopulate_field_setting', 'error_message_setting', 'label_setting', 'label_placement_setting', 'admin_label_setting', 'maxlen_setting', 'size_setting', 'rules_setting', 'visibility_setting', 'duplicate_setting', 'default_value_textarea_setting', 'placeholder_textarea_setting', 'description_setting', 'css_class_setting'); } public function is_conditional_logic_supported() { return true; } public function get_field_input($form, $value = '', $entry = null) { $form_id = absint($form['id']); $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $id = intval($this->id); $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $size = $this->size; $class_suffix = $is_entry_detail ? '_admin' : ''; $class = $size . $class_suffix; $class = esc_attr($class); $disabled_text = $is_form_editor ? 'disabled="disabled"' : ''; $logic_event = $this->get_conditional_logic_event('keyup'); $placeholder_attribute = $this->get_field_placeholder_attribute(); $tabindex = $this->get_tabindex(); $value = esc_textarea($value); return "<div class='ginput_container ginput_container_textarea'>\r\n\t\t\t\t\t<textarea name='input_{$id}' id='{$field_id}' class='textarea {$class}' {$tabindex} {$logic_event} {$placeholder_attribute} {$disabled_text} rows='10' cols='50'>{$value}</textarea>\r\n\t\t\t\t</div>"; } public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br) { return $format == 'html' && !$nl2br ? nl2br($value) : $value; } } GF_Fields::register(new GF_Field_Textarea());
} public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br) { $value = $this->get_display_name($value); return $value; } public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen') { $assignee = parent::get_value_entry_detail($value, $currency, $use_text, $format, $media); $value = $this->get_display_name($assignee); return $value; } public function get_display_name($assignee) { if (empty($assignee)) { return ''; } list($type, $value) = explode('|', $assignee, 2); switch ($type) { case 'role': $value = translate_user_role($value); break; case 'user_id': $user = get_user_by('id', $value); $value = $user->display_name; } return $value; } } GF_Fields::register(new Gravity_Flow_Field_Assignee_Select());
$lead_field_keys = array_keys($entry); foreach ($lead_field_keys as $input_id) { //mark as a tick if input label (from form meta) is equal to submitted value (from lead) if (is_numeric($input_id) && absint($input_id) == absint($field_id)) { $sanitized_value = wp_kses($entry[$input_id], $allowed_tags); $sanitized_label = wp_kses($field_label, $allowed_tags); if ($sanitized_value == $sanitized_label) { return $entry[$input_id]; } else { if ($this->enableChoiceValue || $this->enablePrice) { foreach ($this->choices as $choice) { if ($choice['value'] == $entry[$field_id]) { return $choice['value']; } elseif ($this->enablePrice) { $ary = explode('|', $entry[$field_id]); $val = count($ary) > 0 ? $ary[0] : ''; $price = count($ary) > 1 ? $ary[1] : ''; if ($val == $choice['value']) { return $choice['value']; } } } } } } } return false; } } GF_Fields::register(new GF_Field_Checkbox());
$value .= !empty($caption) ? "<div>Caption: {$caption}</div>" : ''; $value .= !empty($description) ? "<div>Description: {$description}</div>" : ''; break; } } return $value; } public function get_value_submission($field_values, $get_from_post_global_var = true) { $value[$this->id . '.1'] = $this->get_input_value_submission('input_' . $this->id . '_1', $get_from_post_global_var); $value[$this->id . '.4'] = $this->get_input_value_submission('input_' . $this->id . '_4', $get_from_post_global_var); $value[$this->id . '.7'] = $this->get_input_value_submission('input_' . $this->id . '_7', $get_from_post_global_var); return $value; } public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br) { list($url, $title, $caption, $description) = array_pad(explode('|:|', $value), 4, false); switch ($modifier) { case 'title': return $title; case 'caption': return $caption; case 'description': return $description; default: return str_replace(' ', '%20', $url); } } } GF_Fields::register(new GF_Field_Post_Image());
} public function get_field_input($form, $value = '', $entry = null) { $form_id = absint($form['id']); $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $html_input_type = 'text'; if ($this->enablePasswordInput && !$is_entry_detail) { $html_input_type = 'password'; } $logic_event = !$is_form_editor && !$is_entry_detail ? $this->get_conditional_logic_event('keyup') : ''; $id = (int) $this->id; $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $value = esc_attr($value); $size = $this->size; $class_suffix = $is_entry_detail ? '_admin' : ''; $class = $size . $class_suffix; $max_length = is_numeric($this->maxLength) ? "maxlength='{$this->maxLength}'" : ''; $tabindex = $this->get_tabindex(); $disabled_text = $is_form_editor ? 'disabled="disabled"' : ''; $placeholder_attribute = $this->get_field_placeholder_attribute(); $input = "<input name='input_{$id}' id='{$field_id}' type='{$html_input_type}' value='{$value}' class='{$class}' {$max_length} {$tabindex} {$logic_event} {$placeholder_attribute} {$disabled_text}/>"; return sprintf("<div class='ginput_container'>%s</div>", $input); } public function allow_html() { return in_array($this->type, array('post_custom_field', 'post_tags')) ? true : false; } } GF_Fields::register(new GF_Field_Text());
$value = str_replace(' ', '', $value); $card_number_length = strlen($value); $value = substr($value, -4, 4); $value = str_pad($value, $card_number_length, 'X', STR_PAD_LEFT); } elseif ($input_id == '4') { $value = rgpost("input_{$field_id_token}_4"); if (!$value) { $card_number = rgpost("input_{$field_id_token}_1"); $card_type = GFCommon::get_card_type($card_number); $value = $card_type ? $card_type['name'] : ''; } } else { $value = ''; } return $this->sanitize_entry_value($value, $form['id']); } /** * GF1.8 and earlier used 5 inputs (1 input for the expiration date); GF1.9 changed to 6 inputs (the expiration month and year now separate); upgrade those fields still using the older configuration. */ public function maybe_upgrade_inputs() { $inputs = $this->inputs; if (count($inputs) == 5 && $inputs[1]['id'] != $this->id . '.2_month') { $new_inputs = array(array('id' => $this->id . '.2_month', 'label' => esc_html__('Expiration Month', 'gravityforms'), 'defaultLabel' => $inputs[1]['label']), array('id' => $this->id . '.2_year', 'label' => esc_html__('Expiration Year', 'gravityforms'))); array_splice($inputs, 1, 1, $new_inputs); $this->inputs = $inputs; } } } GF_Fields::register(new GF_Field_CreditCard());
return array('post_tag_type_setting', 'conditional_logic_field_setting', 'prepopulate_field_setting', 'error_message_setting', 'label_setting', 'label_placement_setting', 'admin_label_setting', 'size_setting', 'rules_setting', 'default_value_setting', 'visibility_setting', 'description_setting', 'css_class_setting'); } public function is_conditional_logic_supported() { return true; } public function get_field_input($form, $value = '', $entry = null) { $form_id = $form['id']; $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $id = (int) $this->id; $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $value = esc_attr($value); $size = $this->size; $class_suffix = $is_entry_detail ? '_admin' : ''; $class = $size . $class_suffix; $class = esc_attr($class); $disabled_text = $is_form_editor ? 'disabled="disabled"' : ''; $tabindex = $this->get_tabindex(); $logic_event = $this->get_conditional_logic_event('keyup'); $placeholder_attribute = $this->get_field_placeholder_attribute(); return "<div class='ginput_container'>\n\t\t\t\t\t<input name='input_{$id}' id='{$field_id}' type='text' value='{$value}' class='{$class}' {$tabindex} {$logic_event} {$placeholder_attribute} {$disabled_text}/>\n\t\t\t\t</div>"; } public function allow_html() { return true; } } GF_Fields::register(new GF_Field_Post_Tags());
public $type = 'page'; public function get_form_editor_field_title() { return esc_attr__('Page', 'gravityforms'); } function get_form_editor_field_settings() { return array('next_button_setting', 'previous_button_setting', 'css_class_setting', 'conditional_logic_page_setting', 'conditional_logic_nextbutton_setting'); } public function get_field_content($value, $force_frontend_label, $form) { $admin_buttons = $this->get_admin_buttons(); $field_content = "{$admin_buttons} <label class='gfield_label'> </label><div class='gf-pagebreak-inline gf-pagebreak-container'><div class='gf-pagebreak-text-before'>" . esc_html__('end of page', 'gravityforms') . "</div><div class='gf-pagebreak-text-main'><span>" . esc_html__('PAGE BREAK', 'gravityforms') . "</span></div><div class='gf-pagebreak-text-after'>" . esc_html__('top of new page', 'gravityforms') . '</div></div>'; return $field_content; } public function sanitize_settings() { parent::sanitize_settings(); if ($this->nextButton) { $this->nextButton['imageUrl'] = wp_strip_all_tags($this->nextButton['imageUrl']); $allowed_tags = wp_kses_allowed_html('post'); $this->nextButton['text'] = wp_kses($this->nextButton['text'], $allowed_tags); $this->nextButton['type'] = wp_strip_all_tags($this->nextButton['type']); if (isset($this->nextButton['conditionalLogic']) && is_array($this->nextButton['conditionalLogic'])) { $this->nextButton['conditionalLogic'] = $this->sanitize_settings_conditional_logic($this->nextButton['conditionalLogic']); } } } } GF_Fields::register(new GF_Field_Page());
$quantity_field = " <span class='ginput_quantity_label' {$style}>{$product_quantity_sub_label}</span> <input type='{$qty_input_type}' name='input_{$id}.3' value='{$quantity}' id='ginput_quantity_{$form_id}_{$this->id}' class='ginput_quantity' size='10' {$disabled_text}/>"; } else { if (!$this->disableQuantity) { $tabindex = $this->get_tabindex(); $quantity_field .= " <span class='ginput_quantity_label'>" . $product_quantity_sub_label . "</span> <input type='{$qty_input_type}' name='input_{$id}.3' value='{$quantity}' id='ginput_quantity_{$form_id}_{$this->id}' class='ginput_quantity' size='10' {$qty_min_attr} {$tabindex}/>"; } else { if (!is_numeric($quantity)) { $quantity = 1; } if (!$has_quantity) { $quantity_field .= "<input type='hidden' name='input_{$id}.3' value='{$quantity}' class='ginput_quantity_{$form_id}_{$this->id} gform_hidden' />"; } } } return "<div class='ginput_container'>\n\t\t\t\t\t<input type='hidden' name='input_{$id}.1' value='{$product_name}' class='gform_hidden' />\n\t\t\t\t\t<span class='ginput_product_price_label'>" . apply_filters("gform_product_price_{$form_id}", apply_filters('gform_product_price', __('Price', 'gravityforms'), $form_id), $form_id) . ":</span> <span class='ginput_product_price' id='{$field_id}'>" . esc_html(GFCommon::to_money($price, $currency)) . "</span>\n\t\t\t\t\t<input type='hidden' name='input_{$id}.2' id='ginput_base_price_{$form_id}_{$this->id}' class='gform_hidden' value='" . esc_attr($price) . "'/>\n\t\t\t\t\t{$quantity_field}\n\t\t\t\t</div>"; } public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen') { if (is_array($value) && !empty($value)) { $product_name = trim($value[$this->id . '.1']); $price = trim($value[$this->id . '.2']); $quantity = trim($value[$this->id . '.3']); $product = $product_name . ', ' . __('Qty: ', 'gravityforms') . $quantity . ', ' . __('Price: ', 'gravityforms') . $price; return $product; } else { return ''; } } } GF_Fields::register(new GF_Field_SingleProduct());
return array('conditional_logic_field_setting', 'prepopulate_field_setting', 'error_message_setting', 'label_setting', 'label_placement_setting', 'admin_label_setting', 'post_title_template_setting', 'post_status_setting', 'post_category_setting', 'size_setting', 'rules_setting', 'visibility_setting', 'default_value_setting', 'placeholder_setting', 'description_setting', 'css_class_setting', 'post_author_setting', 'post_format_setting'); } public function is_conditional_logic_supported() { return true; } public function get_field_input($form, $value = '', $entry = null) { $form_id = $form['id']; $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $id = (int) $this->id; $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $value = esc_attr($value); $size = $this->size; $class_suffix = $is_entry_detail ? '_admin' : ''; $class = $size . $class_suffix; $class = esc_attr($class); $disabled_text = $is_form_editor ? 'disabled="disabled"' : ''; $tabindex = $this->get_tabindex(); $logic_event = $this->get_conditional_logic_event('keyup'); $placeholder_attribute = $this->get_field_placeholder_attribute(); return "<div class='ginput_container ginput_container_post_title'>\n\t\t\t\t\t<input name='input_{$id}' id='{$field_id}' type='text' value='{$value}' class='{$class}' {$tabindex} {$logic_event} {$placeholder_attribute} {$disabled_text}/>\n\t\t\t\t</div>"; } public function allow_html() { return true; } } GF_Fields::register(new GF_Field_Post_Title());
parent::sanitize_settings(); $this->maxRows = absint($this->maxRows); } public function get_value_export($entry, $input_id = '', $use_text = false, $is_csv = false) { if (empty($input_id)) { $input_id = $this->id; } elseif (!ctype_digit($input_id)) { $field_id_array = explode('.', $input_id); $input_id = rgar($field_id_array, 0); $column_num = rgar($field_id_array, 1); } $value = rgar($entry, $input_id); if (empty($value) || $is_csv) { return $value; } $list_values = $column_values = unserialize($value); if (isset($column_num) && is_numeric($column_num) && $this->enableColumns) { $column = rgars($this->choices, "{$column_num}/text"); $column_values = array(); foreach ($list_values as $value) { $column_values[] = rgar($value, $column); } } elseif ($this->enableColumns) { return json_encode($list_values); } return GFCommon::implode_non_blank(', ', $column_values); } } GF_Fields::register(new GF_Field_List());
<?php if (!class_exists('GFForms')) { die; } class GF_Field_Quantity extends GF_Field { public $type = 'quantity'; function get_form_editor_field_settings() { return array('product_field_setting', 'quantity_field_type_setting', 'conditional_logic_field_setting', 'prepopulate_field_setting', 'label_setting', 'admin_label_setting', 'label_placement_setting', 'default_value_setting', 'placeholder_setting', 'description_setting', 'css_class_setting'); } public function get_form_editor_field_title() { return esc_attr__('Quantity', 'gravityforms'); } } GF_Fields::register(new GF_Field_Quantity());
} $word = $captcha->generate_random_word(); $prefix = mt_rand(); $filename = $captcha->generate_image($prefix, $word); $url = RGFormsModel::get_upload_url('captcha') . '/' . $filename; $path = $captcha->tmp_dir . $filename; if (GFCommon::is_ssl() && strpos($url, 'http:') !== false) { $url = str_replace('http:', 'https:', $url); } return array('path' => $path, 'url' => $url, 'height' => $captcha->img_size[1], 'width' => $captcha->img_size[0], 'prefix' => $prefix); } private function hex2rgb($color) { if ($color[0] == '#') { $color = substr($color, 1); } if (strlen($color) == 6) { list($r, $g, $b) = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]); } elseif (strlen($color) == 3) { list($r, $g, $b) = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]); } else { return false; } $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); return array($r, $g, $b); } } GF_Fields::register(new GF_Field_CAPTCHA());
{ if (is_array($value) && !empty($value)) { $product_name = trim($value[$this->id . '.1']); $price = trim($value[$this->id . '.2']); $quantity = trim($value[$this->id . '.3']); $product = $product_name . ', ' . esc_html__('Qty: ', 'gravityforms') . $quantity . ', ' . esc_html__('Price: ', 'gravityforms') . $price; return $product; } else { return ''; } } public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead) { // ignore submitted value and recalculate price in backend list($prefix, $field_id, $input_id) = rgexplode('_', $input_name, 3); if ($input_id == 2) { require_once GFCommon::get_base_path() . '/currency.php'; $currency = new RGCurrency(GFCommon::get_currency()); $lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead; $value = $currency->to_money(GFCommon::calculate($this, $form, $lead)); } return $value; } public function sanitize_settings() { parent::sanitize_settings(); $this->enableCalculation = (bool) $this->enableCalculation; } } GF_Fields::register(new GF_Field_Calculation());
return true; } public function get_field_input($form, $value = '', $entry = null) { $form_id = $form['id']; $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $id = (int) $this->id; $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $value = esc_textarea($value); $size = $this->size; $class_suffix = $is_entry_detail ? '_admin' : ''; $class = $size . $class_suffix; $class = esc_attr($class); $disabled_text = $is_form_editor ? 'disabled="disabled"' : ''; $tabindex = $this->get_tabindex(); $logic_event = $this->get_conditional_logic_event('keyup'); $placeholder_attribute = $this->get_field_placeholder_attribute(); return "<div class='ginput_container'>\n\t\t\t\t\t<textarea name='input_{$id}' id='{$field_id}' class='textarea {$class}' {$tabindex} {$logic_event} {$placeholder_attribute} {$disabled_text} rows='10' cols='50'>{$value}</textarea>\n\t\t\t\t</div>"; } public function allow_html() { return true; } public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br) { return $format == 'html' && !$nl2br ? nl2br($value) : $value; } } GF_Fields::register(new GF_Field_Post_Content());
{ return array(); } public function get_field_input($form, $value = '', $entry = null) { $form_id = $form['id']; $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $id = (int) $this->id; $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $currency = $is_entry_detail && !empty($entry) ? $entry['currency'] : ''; $price = !empty($value) ? $value : $this->basePrice; if (empty($price)) { $price = 0; } return "<div class='ginput_container'>\n\t\t\t\t\t<input type='hidden' name='input_{$id}' value='{$price}' class='gform_hidden'/>\n\t\t\t\t\t<span class='ginput_shipping_price' id='{$field_id}'>" . GFCommon::to_money($price, $currency) . '</span> </div>'; } public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen') { return GFCommon::to_money($value, $currency); } public function sanitize_settings() { parent::sanitize_settings(); $price_number = GFCommon::to_number($this->basePrice); $this->basePrice = GFCommon::to_money($price_number); } } GF_Fields::register(new GF_Field_SingleShipping());
$tooltips['form_field_repeater_end_hideButtons'] = "If enabled, no add and remove buttons will be displayed. This is useful if you plan on using custom javascript to trigger the repeater."; return $tooltips; } public function get_field_content($value, $force_frontend_label, $form) { if (is_admin()) { $admin_buttons = $this->get_admin_buttons(); $field_content = "{$admin_buttons}\n\t\t\t\t\t\t\t<div class=\"gf-pagebreak-end gf-pagebreak-container gf-repeater-end\">\n\t\t\t\t\t\t\t\t<div class=\"gf-pagebreak-text-before\">end repeater</div>\n\t\t\t\t\t\t\t\t<div class=\"gf-pagebreak-text-main\"><span>REPEATER</span></div>\n\t\t\t\t\t\t\t\t<div class=\"gf-pagebreak-text-after\">end of repeater</div>\n\t\t\t\t\t\t\t</div>"; } else { $add_html = $this->add; $remove_html = $this->remove; $hideButtons = $this->hideButtons; $tabindex = GFCommon::get_tabindex(); if (empty($add_html)) { $add_html = "<img class=\"gf_repeater_add_default\" alt=\"+\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\">"; } if (empty($remove_html)) { $remove_html = "<img class=\"gf_repeater_remove_default\" alt=\"-\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\">"; } $field_content = "<div class=\"ginput_container ginput_container_repeater-end\">\n"; if (!$hideButtons) { $field_content .= "<span class=\"gf_repeater_remove\" {$tabindex}>{$remove_html}</span>"; $field_content .= "<span class=\"gf_repeater_add\" {$tabindex}>{$add_html}</span>"; } $field_content .= "</div>"; } return $field_content; } } GF_Fields::register(new GF_Field_Repeater_End());
function set_permissions($path) { GFCommon::log_debug(__METHOD__ . '(): Setting permissions on: ' . $path); GFFormsModel::set_permissions($path); } public function sanitize_settings() { parent::sanitize_settings(); if ($this->maxFileSize) { $this->maxFileSize = absint($this->maxFileSize); } if ($this->maxFiles) { $this->maxFiles = preg_replace('/[^0-9,.]/', '', $this->maxFiles); } $this->multipleFiles = (bool) $this->multipleFiles; $this->allowedExtensions = sanitize_text_field($this->allowedExtensions); } public function get_value_export($entry, $input_id = '', $use_text = false, $is_csv = false) { if (empty($input_id)) { $input_id = $this->id; } $value = rgar($entry, $input_id); if ($this->multipleFiles && !empty($value)) { return implode(' , ', json_decode($value, true)); } return $value; } } GF_Fields::register(new GF_Field_FileUpload());
$address_qs = str_replace($line_break, ' ', $address); //replacing <br/> and \n with spaces $address_qs = urlencode($address_qs); $address .= "<br/><a href='http://maps.google.com/maps?q={$address_qs}' target='_blank' class='map-it-link'>Map It</a>"; } return $address; } else { return ''; } } public function get_input_property($input_id, $property_name) { $input = GFFormsModel::get_input($this, $input_id); return rgar($input, $property_name); } public function sanitize_settings() { parent::sanitize_settings(); if ($this->addressType) { $this->addressType = wp_strip_all_tags($this->addressType); } if ($this->defaultCountry) { $this->defaultCountry = wp_strip_all_tags($this->defaultCountry); } if ($this->defaultProvince) { $this->defaultProvince = wp_strip_all_tags($this->defaultProvince); } } } GF_Fields::register(new GF_Field_Address());