/** * Return a Gravity Forms field array, whether using GF 1.9 or not * * @since 1.7 * * @param array|GF_Fields $field Gravity Forms field or array * @return array Array version of $field */ public static function get_field_array($field) { if (class_exists('GF_Fields')) { $field_object = GF_Fields::create($field); // Convert the field object in 1.9 to an array for backward compatibility $field_array = get_object_vars($field_object); } else { $field_array = $field; } return $field_array; }
/** * 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()); }); }
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());
?> ), new Choice(<?php echo json_encode(esc_html__('Third Choice', 'gravityforms')); ?> )); } break; case "address" : if (!field.label) field.label = <?php echo json_encode(esc_html__('Address', 'gravityforms')); ?> ; field.addressType = <?php echo json_encode(GF_Fields::get('address')->get_default_address_type(rgget('id'))); ?> ; field.inputs = [new Input(field.id + 0.1, <?php echo json_encode(gf_apply_filters(array('gform_address_street', rgget('id')), esc_html__('Street Address', 'gravityforms'), rgget('id'))); ?> ), new Input(field.id + 0.2, <?php echo json_encode(gf_apply_filters(array('gform_address_street2', rgget('id')), esc_html__('Address Line 2', 'gravityforms'), rgget('id'))); ?> ), new Input(field.id + 0.3, <?php echo json_encode(gf_apply_filters(array('gform_address_city', rgget('id')), esc_html__('City', 'gravityforms'), rgget('id'))); ?> ), new Input(field.id + 0.4, <?php echo json_encode(gf_apply_filters(array('gform_address_state', rgget('id')), __('State / Province', 'gravityforms'), rgget('id'))); ?>
{ 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());
public static function captcha_image() { $field_properties = array('type' => 'captcha', 'simpleCaptchaSize' => $_GET['size'], 'simpleCaptchaFontColor' => $_GET['fg'], 'simpleCaptchaBackgroundColor' => $_GET['bg']); /* @var GF_Field_CAPTCHA $field */ $field = GF_Fields::create($field_properties); if ($_GET['type'] == 'math') { $captcha = $field->get_math_captcha($_GET['pos']); } else { $captcha = $field->get_captcha(); } @ini_set('memory_limit', '256M'); $image = imagecreatefrompng($captcha['path']); include_once ABSPATH . 'wp-admin/includes/image-edit.php'; wp_stream_image($image, 'image/png', 0); imagedestroy($image); die; }
private static function get_honeypot_field($form) { $max_id = self::get_max_field_id($form); $labels = self::get_honeypot_labels(); $properties = array('type' => 'honeypot', 'label' => $labels[rand(0, 3)], 'id' => $max_id + 1, 'cssClass' => 'gform_validation_container', 'description' => __('This field is for validation purposes and should be left unchanged.', 'gravityforms')); $field = GF_Fields::create($properties); return $field; }
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());
/** * Returns the combined value of the specified Name field. * * @param array $entry * @param string $field_id * * @return string */ public function get_full_name($entry, $field_id) { return GF_Fields::get('name')->get_value_export($entry, $field_id); }
} 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());
$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());
$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());
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());
} $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());
public static function output_field_scripts($echo = true) { $script_str = ''; $conditional_logic_fields = array(); foreach (GF_Fields::get_all() as $gf_field) { if ($gf_field->is_conditional_logic_supported()) { $conditional_logic_fields[] = $gf_field->type; } } $script_str .= sprintf('function GetConditionalLogicFields(){return %s;}', json_encode($conditional_logic_fields)) . PHP_EOL; if (!empty($script_str) && $echo) { echo $script_str; } return $script_str; }
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());
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());
<?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());
{ 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());
public static function inline_scripts($echo = true) { $script_str = ''; $conditional_logic_fields = array(); $field_settings = array(); foreach (GF_Fields::get_all() as $gf_field) { $settings_arr = $gf_field->get_form_editor_field_settings(); if (!is_array($settings_arr) || empty($settings_arr)) { continue; } $settings = join(', .', $settings_arr); $settings = '.' . $settings; $field_settings[$gf_field->type] = $settings; if ($gf_field->is_conditional_logic_supported()) { $conditional_logic_fields[] = $gf_field->type; } $field_script = $gf_field->get_form_editor_inline_script_on_page_render(); if (!empty($field_script)) { $script_str .= $field_script . PHP_EOL; } } $script_str .= sprintf('fieldSettings = %s;', json_encode($field_settings)) . PHP_EOL; $script_str .= sprintf('function GetConditionalLogicFields(){return %s;}', json_encode($conditional_logic_fields)) . PHP_EOL; if (!empty($script_str)) { $script_str = sprintf('<script type="text/javascript">%s</script>', $script_str); if ($echo) { echo $script_str; } } return $script_str; }
$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());
/** * @param GF_Field $field * @param int $input_id * @param bool $input_only * * @return string */ public static function get_label($field, $input_id = 0, $input_only = false, $allow_admin_label = true) { if (!$field instanceof GF_Field) { $field = GF_Fields::create($field); } $field_label = (IS_ADMIN || RG_CURRENT_PAGE == 'select_columns.php' || RG_CURRENT_PAGE == 'print-entry.php' || rgget('gf_page', $_GET) == 'select_columns' || rgget('gf_page', $_GET) == 'print-entry') && !empty($field->adminLabel) && $allow_admin_label ? $field->adminLabel : $field->label; $input = self::get_input($field, $input_id); if (self::get_input_type($field) == 'checkbox' && $input != null) { return $input['label']; } else { if ($input != null) { return $input_only ? $input['label'] : $field_label . ' (' . $input['label'] . ')'; } else { return $field_label; } } }
$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());
$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());
{ $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());
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());
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());
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());
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());