/** * This function render the single field * @global type $post * @param type $field * @param type $add2form_content * @return type */ public function renderField($field, $add2form_content = false) { global $post; //echo "<br>{$field['name']}"; if (defined('WPTOOLSET_FORMS_ABSPATH') && function_exists('wptoolset_form_field')) { require_once WPTOOLSET_FORMS_ABSPATH . '/api.php'; require_once WPTOOLSET_FORMS_ABSPATH . '/classes/class.fieldconfig.php'; require_once WPTOOLSET_FORMS_ABSPATH . '/classes/class.types.php'; require_once WPTOOLSET_FORMS_ABSPATH . '/classes/class.cred.php'; $id = $this->form_id; $field['id'] = $id; if ($field['type'] == 'messages') { $this->isForm = true; return; } if ($this->form_type == 'edit' && $field['name'] == 'user_login') { $field['attr']['readonly'] = "readonly"; $field['attr']['style'] = "background-color:#ddd;"; $field['attr']['onclick'] = "blur();"; } if ($field['type'] == 'credfile' || $field['type'] == 'credaudio' || $field['type'] == 'credvideo' || $field['type'] == 'credimage' || $field['type'] == 'file') { $this->isUploadForm = true; //$field['type'] = 'credfile'; } /* $validation = array( 'validation' => array( 'required' => array( 'args' => array($field['value'], true), 'message' => 'Required'), 'maxlength' => array( 'args' => array($field['value'], 12), 'message' => 'maxlength of 12 exceeded' ), 'rangelength' => array( 'args' => array($field['value'], 3, 25), 'message' => 'input range from 3 to 25' ), )); */ //############################################################################################################################################################# //Client-side validation is not using the custom messages provided in CRED forms for CRED custom fields //https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/187800735/comments $this->fixCredCustomFieldMessages($field); //############################################################################################################################################################# $mytype = $this->transType($field['type']); $fieldConfig = new FieldConfig(); $fieldConfig->setDefaultValue($field['type'], $field); $fieldConfig->setOptions($field['name'], $field['type'], $field['value'], $field['attr']); $fieldConfig->setId($this->form_properties['name'] . "_" . $field['name']); $fieldConfig->setName($field['name']); $this->cleanAttr($field['attr']); $fieldConfig->setAttr($field['attr']); $_curr_value = ""; //############################################################################################################################################################# //Fix https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/192427784/comments#300129108 //losting filled data if using hook validate system if (isset($this->controls[$field['name']]) && !empty($this->controls[$field['name']])) { $_curr_value = $this->controls[$field['name']]; } else { if (isset($field['value']) && !empty($field['value'])) { $_curr_value = $field['value']; } } //############################################################################################################################################################# if (!$this->is_submit_success && ($mytype != 'credfile' && $mytype != 'credaudio' && $mytype != 'credvideo' && $mytype != 'credimage')) { $_curr_value = isset($this->controls[$field['name']]) ? $this->controls[$field['name']] : $field['value']; } else { if (isset($field['attr']['preset_value']) && !empty($field['attr']['preset_value'])) { $_curr_value = $field['attr']['preset_value']; } } $fieldConfig->setValue($_curr_value); $fieldConfig->setDescription(!empty($field['description']) ? $field['description'] : ""); $fieldConfig->setTitle($field['title']); $fieldConfig->setType($mytype); if (isset($field['data']) && isset($field['data']['repetitive'])) { $fieldConfig->setRepetitive((bool) $field['data']['repetitive']); } if (isset($field['attr']) && isset($field['attr']['type'])) { $fieldConfig->setDisplay($field['attr']['type']); } $config = $fieldConfig->createConfig(); // Modified by Srdjan // Validation and conditional filtering if (isset($field['plugin_type']) && $field['plugin_type'] == 'types') { // This is not set in DB $field['meta_key'] = WPToolset_Types::getMetakey($field); $config['validation'] = WPToolset_Types::filterValidation($field); if ($post) { $config['conditional'] = WPToolset_Types::filterConditional($field, $post->ID); } } else { $config['validation'] = WPToolset_Cred::filterValidation($field); } // Modified by Srdjan END $_values = array(); if (isset($field['data']['repetitive']) && $field['data']['repetitive'] == 1) { //$_values = $field['value']; $_values = $_curr_value; } else { //$_values = array($field['value']); $_values = array($_curr_value); } // Added by Srdjan /* * Use $_validation_errors * set in $this::validate() */ if (isset($this->_validation_errors['fields'][$config['id']])) { $config['validation_error'] = $this->_validation_errors['fields'][$config['id']]; } if ($this->form_type == 'edit' && $mytype == 'checkbox') { unset($config['default_value']); } // Added by Srdjan END $html = wptoolset_form_field($this->form_id, $config, $_values); if ($add2form_content) { $this->_form_content .= $html; } else { return $html; } /* <input id="cred_form_853_1__cred_cred_wpnonce" type="hidden" user_defined="" value="d9f46d7082" name="_cred_cred_wpnonce"> <input id="cred_form_853_1__cred_cred_prefix_form_id" type="hidden" user_defined="" value="853" name="_cred_cred_prefix_form_id"> <input id="cred_form_853_1__cred_cred_prefix_form_count" type="hidden" user_defined="" value="1" name="_cred_cred_prefix_form_count"> <input id="cred_form_853_1_name_cred_form_853_1" type="hidden" user_defined="" value="cred_form_853_1" name="name_cred_form_853_1"> */ } }