'advanced_fields', 'text' => $this->get_form_editor_field_title() ); } /** * Defines the field settings available within the field editor. * * @since Unknown * @access public * * @return array The field settings available for the field. */ function get_form_editor_field_settings() { return array( 'conditional_logic_field_setting', 'prepopulate_field_setting', 'error_message_setting', 'label_setting', 'field_field_repeater_end_text_setting', 'field_field_repeater_initial_rows_setting', 'field_field_repeater_max_setting', 'label_placement_setting', 'admin_label_setting', 'size_setting', 'rules_setting', 'visibility_setting', 'duplicate_setting', 'placeholder_setting', 'description_setting', 'css_class_setting', ); } /** * Defines if conditional logic is supported in this field type. * * @since Unknown * @access public * * @used-by GFFormDetail::inline_scripts() * @used-by GFFormSettings::output_field_scripts() * * @return bool true */ public function is_conditional_logic_supported() { return false; } /** * Returns the field input. * * @since Unknown * @access public * * @used-by GFCommon::get_field_input() * @uses GF_Field::is_entry_detail() * @uses GF_Field::is_form_editor() * @uses GF_Field_Phone::$failed_validation * @uses GF_Field_Phone::get_phone_format() * @uses GFFormsModel::is_html5_enabled() * @uses GF_Field::get_field_placeholder_attribute() * @uses GF_Field_Phone::$isRequired * @uses GF_Field::get_tabindex() * * @param array $form The Form Object. * @param string $value The value of the input. Defaults to empty string. * @param null|array $entry The Entry Object. Defaults to null. * * @return string The HTML markup for the field. */ public function get_field_input( $form, $value = '', $entry = null ) { $check_pro = get_option( '_redmuber_item_1540'); if ( is_array( $value ) ) { $value = ''; } $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $form_id = $form['id']; $id = intval( $this->id ); $field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_$id" : 'input_' . $form_id . "_$id"; $size = $this->size; $disabled_text = $is_form_editor ? "disabled='disabled'" : ''; $class_suffix = $is_entry_detail ? '_admin' : ''; $class = $size . $class_suffix. " gf-field-repeater-data hidden"; $class = esc_attr( $class ); $instruction_div = ''; $html_input_type = 'hidden'; $placeholder_attribute = $this->get_field_placeholder_attribute(); $required_attribute = $this->isRequired ? 'aria-required="true"' : ''; $invalid_attribute = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"'; $aria_describedby = $this->get_aria_describedby(); $tabindex = $this->get_tabindex(); $repeater_add_button = $this->field_repeater_end_text; if($repeater_add_button == ""){ $repeater_add_button = esc_attr__("Add more","gravityforms-repeater"); } $initial_rows = $this->repeater_initial_rows; if( $initial_rows == ""){ $initial_rows = 0; } $limit = $this->repeater_max; if( $limit == "" or $limit < 1){ $limit = 9999; } if($check_pro != "ok" ){ if( $limit > 5) { $limit = 5; } $initial_rows = 1; } $input = ""; $html ='
'.$input.'
'; if (is_admin()) { $html = '
End Repeater
'; return sprintf( "
%s
", $html); }else{ return sprintf( "
%s
", $html); } } public static function remove_validation($form) { $zo = false; $zo_datas = array(); foreach( $form["fields"] as $field ){ $type = $field->type; if( $type == "repeater_start"){ $zo = true; continue; } if( $type == "repeater_end"){ $zo = false; continue; } if( $zo ){ if( !isset($field->repeater_validate )) { $field->repeater_validate = array("isRequired"=>$field->isRequired); } $field->isRequired = false; } } return $form; } function validate($value, $form) { $datas = json_decode($value, true); $list_fields_validate = array(); $failedValidation = false; foreach( $form["fields"] as $field ){ if( is_array($field->repeater_validate)) { foreach( $field->repeater_validate as $k=>$v ){ if($k=="isRequired" && $v == true) { $list_fields_validate["input_".$field->id] = $field->type; } } } } if( isset($datas["id"]) && is_array($datas["id"])) { foreach( $datas["id"] as $id ){ foreach( $datas["fields"] as $field ){ if( isset($list_fields_validate[$field]) ){ $getInputData = rgpost($field."__".$id); switch($list_fields_validate[$field]){ case "name": $first_name = rgpost($field."_3__".$id); $last_name = rgpost($field."_6__".$id); if ( empty($first_name) || empty($last_name) ) { $failedValidation = true; } break; case 'address': $address = rgpost($field."_1__".$id); if ( empty($address) ) { $failedValidation = true; } break; default: if (empty($getInputData)) { $failedValidation = true; } break; } } } } if ($failedValidation) { $this->failed_validation = true; if ($this->errorMessage) { $this->validation_message = $this->errorMessage; } else { $this->validation_message = "This field is required."; } return; }else{ $this->failed_validation = false; } } } function custom_validation($form){ $dataRepeater = array(); $zo = false; $zo_datas = array(); foreach( $form["fields"] as $field ){ $type = $field->type; if( $type == "repeater_start"){ $zo = true; continue; } if( $zo ){ $zo_datas[$field->id] = array("isRequired"=>$field->isRequired); $field->isRequired = false; } if( $type == "repeater_end"){ $zo = false; $zo_datas = array(); continue; } } return $form; } /** * Gets the value of the submitted field. * * @since Unknown * @access public * * @used-by GFFormsModel::get_field_value() * @uses GF_Field::get_value_submission() * @uses GF_Field_Phone::sanitize_entry_value() * * @param array $field_values The dynamic population parameter names with their corresponding values to be populated. * @param bool $get_from_post_global_var Whether to get the value from the $_POST array as opposed to $field_values. Defaults to true. * * @return array|string */ public function get_value_submission( $field_values, $get_from_post_global_var = true ) { $value = parent::get_value_submission( $field_values, $get_from_post_global_var ); $value = $this->sanitize_entry_value( $value, $this->formId ); return $value; } /** * Sanitizes the entry value. * * @since Unknown * @access public * * @used-by GF_Field_Phone::get_value_save_entry() * @used-by GF_Field_Phone::get_value_submission() * * @param string $value The value to be sanitized. * @param int $form_id The form ID of the submitted item. * * @return string The sanitized value. */ public function sanitize_entry_value( $value, $form_id ) { $value = is_array( $value ) ? array_map( 'sanitize_text_field', $value ) : sanitize_text_field( $value ); return $value; } /** * Gets the field value when an entry is being saved. * * @since Unknown * @access public * * @used-by GFFormsModel::prepare_value() * @uses GF_Field_Phone::sanitize_entry_value() * @uses GF_Field_Phone::$phoneFormat * * @param string $value The input value. * @param array $form The Form Object. * @param string $input_name The input name. * @param int $lead_id The Entry ID. * @param array $lead The Entry Object. * * @return string The field value. */ public function get_value_save_entry( $value, $form, $input_name, $lead_id, $lead ) { $check_pro = get_option( '_redmuber_item_1540'); $this->lead_id = $lead_id; $datas = json_decode($value, true); $values = array(); $form_id = $this->formId; $get_form = GFFormsModel::get_form_meta_by_id($form_id); $form = $get_form[0]; $fields = array(); foreach ( $datas["fields"] as $f ){ $datas_f = explode(".",$f); $fields[] = $datas_f[0]; } $fields = array_unique($fields); foreach( $datas["id"] as $id_rand){ $datas_step = array(); foreach( $fields as $field ){ $inputs =$this->get_inputs($form,$field); if( is_array($inputs)) { $getInputData = array(); foreach( $inputs as $child_input ){ $getInputName = "input_".$child_input["id"]."__".$id_rand; $vl = rgpost( str_replace('.', '_', strval($getInputName)) ); if($vl != ""){ $getInputData[$child_input["id"]] = $vl; } } $datas_step[$getInputName] = $getInputData; }else{ $getInputName = $field."__".$id_rand; if(isset($_FILES[ $getInputName ])){ if($check_pro == "ok"){ $datas_step[$getInputName] = $this->upload_file( $form_id, $_FILES[ $getInputName ] ); }else{ $datas_step[$getInputName] = "Upgrade to pro version"; } }else if( isset($_POST[ $getInputName ]) ){ $datas_step[$getInputName] = rgpost( str_replace('.', '_', strval($getInputName)) ); } else{ $getInputData = rgpost( str_replace('.', '_', strval($getInputName)) ); $datas_step[$getInputName] = $getInputData; } } } $values[$id_rand] = $datas_step; } return maybe_serialize($values); } public function upload_file( $form_id, $file ) { GFCommon::log_debug( __METHOD__ . '(): Uploading file: ' . $file['name'] ); $target = GFFormsModel::get_file_upload_path( $form_id, $file['name'] ); if ( ! $target ) { GFCommon::log_debug( __METHOD__ . '(): FAILED (Upload folder could not be created.)' ); return 'FAILED (Upload folder could not be created.)'; } GFCommon::log_debug( __METHOD__ . '(): Upload folder is ' . print_r( $target, true ) ); if ( move_uploaded_file( $file['tmp_name'], $target['path'] ) ) { GFCommon::log_debug( __METHOD__ . '(): File ' . $file['tmp_name'] . ' successfully moved to ' . $target['path'] . '.' ); $this->set_permissions( $target['path'] ); return $target['url']; } else { GFCommon::log_debug( __METHOD__ . '(): FAILED (Temporary file ' . $file['tmp_name'] . ' could not be copied to ' . $target['path'] . '.)' ); return 'FAILED (Temporary file could not be copied.)'; } } function set_permissions( $path ) { GFCommon::log_debug( __METHOD__ . '(): Setting permissions on: ' . $path ); GFFormsModel::set_permissions( $path ); } public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) { if (empty($value)) { return ''; } else { $dataArray = GFFormsModel::unserialize($value); $arrayCount = count($dataArray); if ($arrayCount > 1) { $returnText = $arrayCount.' entries'; } else { $returnText = $arrayCount.' entry'; } return $returnText; } } function get_datas_field($format="html",$value='',$form_id=""){ global $wpdb; $dataArray = GFFormsModel::unserialize($value); $get_form = GFFormsModel::get_form_meta_by_id($form_id); $form = $get_form[0]; if(isset($_GET['lid'])){ $result = GFAPI::get_entry( $_GET['lid'] ); }else{ $table = $wpdb->prefix."gf_entry"; $mylink = $wpdb->get_row( "SELECT id FROM $table ORDER BY id DESC" ); $result = GFAPI::get_entry( $mylink->id ); } if ( $format === 'html' ) { $html = '
    '; foreach( $dataArray as $step_datas ){ $html .= '
  1. '; } $html .= '
      '; $html = apply_filters( "yeeadons_gravity_forms_repeater_html",$html,$dataArray, $form); return $html; }else{ return $value; } } public function get_value_export( $entry, $input_id = '', $use_text = false, $is_csv = false ) { //Export doesn’t require encoding, but field data may require some manipulation or formatting before it is exported $return = $this->get_datas_field("text",$entry,$form_id); return $return; } public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) { if (empty($value)) { return ''; } $form_id = isset( $form['id'] ) ? absint( $form['id'] ) : null; $return = $this->get_datas_field($format,$value,$form_id); return $return; } public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) { global $wpdb; if (empty($value)) { return ''; }else{ $form_id = $this->formId; $return = $this->get_datas_field($format,$value,$form_id); return $return; } } function get_field_label($form, $name = '', $type = '', $child = false, $form_id ='') { if (is_array($form)) { if (!array_key_exists('fields', $form)) { return false; } } else { return false; } $name = str_replace("gform_multifile_upload_".$form_id, "input", $name); $names = explode("__",$name); $names = explode("_",$names[0]); $name = $names[1]; foreach ($form['fields'] as $field_key=>$field_value) { if( is_array($field_value->inputs)){ foreach( $field_value->inputs as $children_id ){ if( $children_id["id"] == $name ) { if( $child ){ return $children_id["label"]; }else{ return $field_value->label; } } } }else{ if( $field_value->id == $name ) { return $field_value->label; } } } return ""; } function get_inputs($form, $name = '') { if (is_array($form)) { if (!array_key_exists('fields', $form)) { return false; } } else { return false; } $names = explode("__",$name); $names = explode("_",$names[0]); $name = $names[1]; foreach ($form['fields'] as $field_key=>$field_value) { if( $field_value->id == $name ) { if( is_array($field_value->inputs)){ return $field_value->inputs; } } } return false; } function get_type($form, $name = '',$form_id ="") { if (is_array($form)) { if (!array_key_exists('fields', $form)) { return false; } } else { return false; } $name = str_replace("gform_multifile_upload_".$form_id, "input", $name); $names = explode("__",$name); $names = explode("_",$names[0]); $name = $names[1]; foreach ($form['fields'] as $field_key=>$field_value) { if( is_array($field_value->inputs)){ foreach( $field_value->inputs as $children_id ){ if( $children_id["id"] == $name ) { return $field_value->type; } } }else{ if( $field_value->id == $name ) { return $field_value->type; } } } return ""; } } // Register the phone field with the field framework. GF_Fields::register( new Superaddons_GFRepeater_Field() );