| @@ -1,0 +1,196 @@ | ||
| 1 | +<?php | |
| 2 | +// If Gravity Forms isn't loaded, bail. | |
| 3 | +if ( ! class_exists( 'GFForms' ) ) { | |
| 4 | + die(); | |
| 5 | +} | |
| 6 | +/** | |
| 7 | + * Class GF_Field_Phone | |
| 8 | + * | |
| 9 | + * Handles the behavior of Phone fields. | |
| 10 | + * | |
| 11 | + * @since Unknown | |
| 12 | + */ | |
| 13 | +class Superaddons_GFRepeater_Start_Field extends GF_Field { | |
| 14 | + /** | |
| 15 | + * Defines the field type. | |
| 16 | + * | |
| 17 | + * @since Unknown | |
| 18 | + * @access public | |
| 19 | + * | |
| 20 | + * @var string The field type. | |
| 21 | + */ | |
| 22 | + public $type = 'repeater_start'; | |
| 23 | + /** | |
| 24 | + * Defines the field title to be used in the form editor. | |
| 25 | + * | |
| 26 | + * @since Unknown | |
| 27 | + * @access public | |
| 28 | + * | |
| 29 | + * @used-by GFCommon::get_field_type_title() | |
| 30 | + * | |
| 31 | + * @return string The field title. Translatable and escaped. | |
| 32 | + */ | |
| 33 | + public function get_form_editor_field_title() { | |
| 34 | + return esc_attr__('Repeater Start', 'repeater-for-gravity-forms' ); | |
| 35 | + } | |
| 36 | + public function get_form_editor_button() { | |
| 37 | + return array( | |
| 38 | + 'group' => 'advanced_fields', | |
| 39 | + 'text' => $this->get_form_editor_field_title() | |
| 40 | + ); | |
| 41 | + } | |
| 42 | + /** | |
| 43 | + * Defines the field settings available within the field editor. | |
| 44 | + * | |
| 45 | + * @since Unknown | |
| 46 | + * @access public | |
| 47 | + * | |
| 48 | + * @return array The field settings available for the field. | |
| 49 | + */ | |
| 50 | + function get_form_editor_field_settings() { | |
| 51 | + return array( | |
| 52 | + 'prepopulate_field_setting', | |
| 53 | + 'label_setting', | |
| 54 | + 'field_field_repeater_title_setting', | |
| 55 | + 'css_class_setting', | |
| 56 | + ); | |
| 57 | + } | |
| 58 | + /** | |
| 59 | + * Defines if conditional logic is supported in this field type. | |
| 60 | + * | |
| 61 | + * @since Unknown | |
| 62 | + * @access public | |
| 63 | + * | |
| 64 | + * @used-by GFFormDetail::inline_scripts() | |
| 65 | + * @used-by GFFormSettings::output_field_scripts() | |
| 66 | + * | |
| 67 | + * @return bool true | |
| 68 | + */ | |
| 69 | + public function is_conditional_logic_supported() { | |
| 70 | + return true; | |
| 71 | + } | |
| 72 | + /** | |
| 73 | + * Returns the field input. | |
| 74 | + * | |
| 75 | + * @since Unknown | |
| 76 | + * @access public | |
| 77 | + * | |
| 78 | + * @used-by GFCommon::get_field_input() | |
| 79 | + * @uses GF_Field::is_entry_detail() | |
| 80 | + * @uses GF_Field::is_form_editor() | |
| 81 | + * @uses GF_Field_Phone::$failed_validation | |
| 82 | + * @uses GF_Field_Phone::get_phone_format() | |
| 83 | + * @uses GFFormsModel::is_html5_enabled() | |
| 84 | + * @uses GF_Field::get_field_placeholder_attribute() | |
| 85 | + * @uses GF_Field_Phone::$isRequired | |
| 86 | + * @uses GF_Field::get_tabindex() | |
| 87 | + * | |
| 88 | + * @param array $form The Form Object. | |
| 89 | + * @param string $value The value of the input. Defaults to empty string. | |
| 90 | + * @param null|array $entry The Entry Object. Defaults to null. | |
| 91 | + * | |
| 92 | + * @return string The HTML markup for the field. | |
| 93 | + */ | |
| 94 | + public function get_field_input( $form, $value = '', $entry = null ) { | |
| 95 | + if ( is_array( $value ) ) { | |
| 96 | + $value = ''; | |
| 97 | + } | |
| 98 | + $is_entry_detail = $this->is_entry_detail(); | |
| 99 | + $is_form_editor = $this->is_form_editor(); | |
| 100 | + $form_id = $form['id']; | |
| 101 | + $id = intval( $this->id ); | |
| 102 | + $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_$id" : 'input_' . $form_id . "_$id"; | |
| 103 | + $size = $this->size; | |
| 104 | + $disabled_text = $is_form_editor ? "disabled='disabled'" : ''; | |
| 105 | + $class_suffix = $is_entry_detail ? '_admin' : ''; | |
| 106 | + $class = $size . $class_suffix. " hidden"; | |
| 107 | + $class = esc_attr( $class ); | |
| 108 | + $repeater_title = $this->repeater_title; | |
| 109 | + $text_input = '<div class="repeater-field-header"> | |
| 110 | + <div class="repeater-field-header-title">'.$repeater_title." "; | |
| 111 | + $text_input .= '<span class="repeater-field-header-count">1</span>'; | |
| 112 | + $text_input .= '</div> | |
| 113 | + <div class="repeater-field-header-acctions"> | |
| 114 | + <ul> | |
| 115 | + <li><i class="repeater-icon icon-down-open repeater-field-header-acctions-toogle" aria-hidden="true"></i></li> | |
| 116 | + <li><i class="repeater-icon icon-cancel-1 repeater-field-header-acctions-remove" aria-hidden="true"></i></li> | |
| 117 | + </ul> | |
| 118 | + </div> | |
| 119 | + </div>'; | |
| 120 | + $text_input = htmlentities($text_input); | |
| 121 | + $html = '<div class="wpforms-field-repeater-start"> | |
| 122 | + <input type="hidden" class="repeater-field-header-data hidden" value="'.$text_input.'" /> | |
| 123 | + </div>'; | |
| 124 | + | |
| 125 | + if (is_admin()) { | |
| 126 | + $html = '<hr>Begin Repeater<hr>'; | |
| 127 | + return sprintf( "<div class='ginput_container1'>%s</div>", $html); | |
| 128 | + }else{ | |
| 129 | + return sprintf( "<div class='ginput_container ginput_container_text'> %s </div>", $html); | |
| 130 | + } | |
| 131 | + } | |
| 132 | + /** | |
| 133 | + * Gets the value of the submitted field. | |
| 134 | + * | |
| 135 | + * @since Unknown | |
| 136 | + * @access public | |
| 137 | + * | |
| 138 | + * @used-by GFFormsModel::get_field_value() | |
| 139 | + * @uses GF_Field::get_value_submission() | |
| 140 | + * @uses GF_Field_Phone::sanitize_entry_value() | |
| 141 | + * | |
| 142 | + * @param array $field_values The dynamic population parameter names with their corresponding values to be populated. | |
| 143 | + * @param bool $get_from_post_global_var Whether to get the value from the $_POST array as opposed to $field_values. Defaults to true. | |
| 144 | + * | |
| 145 | + * @return array|string | |
| 146 | + */ | |
| 147 | + public function get_value_submission( $field_values, $get_from_post_global_var = true ) { | |
| 148 | + return false; | |
| 149 | + } | |
| 150 | + /** | |
| 151 | + * Sanitizes the entry value. | |
| 152 | + * | |
| 153 | + * @since Unknown | |
| 154 | + * @access public | |
| 155 | + * | |
| 156 | + * @used-by GF_Field_Phone::get_value_save_entry() | |
| 157 | + * @used-by GF_Field_Phone::get_value_submission() | |
| 158 | + * | |
| 159 | + * @param string $value The value to be sanitized. | |
| 160 | + * @param int $form_id The form ID of the submitted item. | |
| 161 | + * | |
| 162 | + * @return string The sanitized value. | |
| 163 | + */ | |
| 164 | + public function sanitize_entry_value( $value, $form_id ) { | |
| 165 | + return false; | |
| 166 | + } | |
| 167 | + /** | |
| 168 | + * Gets the field value when an entry is being saved. | |
| 169 | + * | |
| 170 | + * @since Unknown | |
| 171 | + * @access public | |
| 172 | + * | |
| 173 | + * @used-by GFFormsModel::prepare_value() | |
| 174 | + * @uses GF_Field_Phone::sanitize_entry_value() | |
| 175 | + * @uses GF_Field_Phone::$phoneFormat | |
| 176 | + * | |
| 177 | + * @param string $value The input value. | |
| 178 | + * @param array $form The Form Object. | |
| 179 | + * @param string $input_name The input name. | |
| 180 | + * @param int $lead_id The Entry ID. | |
| 181 | + * @param array $lead The Entry Object. | |
| 182 | + * | |
| 183 | + * @return string The field value. | |
| 184 | + */ | |
| 185 | + public function get_value_save_entry( $value, $form, $input_name, $lead_id, $lead ) { | |
| 186 | + return false; | |
| 187 | + } | |
| 188 | + public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) { | |
| 189 | + return false; | |
| 190 | + } | |
| 191 | + public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) { | |
| 192 | + return false; | |
| 193 | + } | |
| 194 | +} | |
| 195 | +// Register the phone field with the field framework. | |
| 196 | +GF_Fields::register( new Superaddons_GFRepeater_Start_Field() ); | |