示例#1
0
 public static function replace_html_shortcodes($html, $field, $atts)
 {
     if ('divider' == $field['type']) {
         global $frm_vars;
         $html = str_replace(array('frm_none_container', 'frm_hidden_container', 'frm_top_container', 'frm_left_container', 'frm_right_container'), '', $html);
         if (isset($frm_vars['collapse_div']) && $frm_vars['collapse_div']) {
             $html = "</div>\n" . $html;
             $frm_vars['collapse_div'] = false;
         }
         if (isset($frm_vars['div']) && $frm_vars['div'] && $frm_vars['div'] != $field['id']) {
             // close the div if it's from a different section
             $html = "</div>\n" . $html;
             $frm_vars['div'] = false;
         }
         if (FrmField::is_option_true($field, 'slide')) {
             $trigger = ' frm_trigger';
             $collapse_div = '<div class="frm_toggle_container" style="display:none;">';
         } else {
             $trigger = $collapse_div = '';
         }
         if (FrmField::is_option_true($field, 'repeat')) {
             $errors = isset($atts['errors']) ? $atts['errors'] : array();
             $field_name = 'item_meta[' . $field['id'] . ']';
             $html_id = FrmFieldsHelper::get_html_id($field);
             $frm_settings = FrmAppHelper::get_settings();
             ob_start();
             include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/input.php';
             $input = ob_get_contents();
             ob_end_clean();
             if (FrmField::is_option_true($field, 'slide')) {
                 $input = $collapse_div . $input . '</div>';
             }
             $html = str_replace('[collapse_this]', $input, $html);
         } else {
             self::remove_close_div($field, $html);
             if (strpos($html, '[collapse_this]') !== false) {
                 $html = str_replace('[collapse_this]', $collapse_div, $html);
                 // indicate that a second div is open
                 if (!empty($collapse_div)) {
                     $frm_vars['collapse_div'] = $field['id'];
                 }
             }
         }
         self::maybe_add_collapse_icon($trigger, $field, $html);
         $html = str_replace('[collapse_class]', $trigger, $html);
     } else {
         if ($field['type'] == 'html') {
             if (apply_filters('frm_use_wpautop', true)) {
                 $html = wpautop($html);
             }
             $html = apply_filters('frm_get_default_value', $html, (object) $field, false);
             $html = do_shortcode($html);
         } else {
             if (FrmField::is_option_true($field, 'conf_field')) {
                 //Add confirmation field
                 //Get confirmation field ready for replace_shortcodes function
                 $conf_html = $field['custom_html'];
                 $conf_field = $field;
                 $conf_field['id'] = 'conf_' . $field['id'];
                 $conf_field['name'] = __('Confirm', 'formidable') . ' ' . $field['name'];
                 $conf_field['description'] = $field['conf_desc'];
                 $conf_field['field_key'] = 'conf_' . $field['field_key'];
                 if ($conf_field['classes']) {
                     $conf_field['classes'] = str_replace('first_', '', $conf_field['classes']);
                 } else {
                     if ($conf_field['conf_field'] == 'inline') {
                         $conf_field['classes'] = ' frm_half';
                     }
                 }
                 //Prevent loop
                 $conf_field['conf_field'] = 'stop';
                 //If inside of repeating section
                 $args = array();
                 if (isset($atts['section_id'])) {
                     $args['field_name'] = preg_replace('/\\[' . $field['id'] . '\\]$/', '', $atts['field_name']);
                     $args['field_name'] = $args['field_name'] . '[conf_' . $field['id'] . ']';
                     $args['field_id'] = 'conf_' . $atts['field_id'];
                     $args['field_plus_id'] = $atts['field_plus_id'];
                     $args['section_id'] = $atts['section_id'];
                 }
                 // Filter default value/placeholder text
                 $field['conf_input'] = apply_filters('frm_get_default_value', $field['conf_input'], (object) $field, false);
                 //If clear on focus, set default value. Otherwise, set value.
                 if ($conf_field['clear_on_focus'] == 1) {
                     $conf_field['default_value'] = $field['conf_input'];
                     $conf_field['value'] = '';
                 } else {
                     $conf_field['value'] = $field['conf_input'];
                 }
                 //If going back and forth between pages, keep value in confirmation field
                 if (isset($_POST['item_meta'])) {
                     $temp_args = array();
                     if (isset($atts['section_id'])) {
                         $temp_args = array('parent_field_id' => $atts['section_id'], 'key_pointer' => str_replace('-', '', $atts['field_plus_id']));
                     }
                     FrmEntriesHelper::get_posted_value($conf_field['id'], $conf_field['value'], $temp_args);
                 }
                 //Replace shortcodes
                 $conf_html = FrmFieldsHelper::replace_shortcodes($conf_html, $conf_field, '', '', $args);
                 //Add a couple of classes
                 $conf_html = str_replace('frm_primary_label', 'frm_primary_label frm_conf_label', $conf_html);
                 $conf_html = str_replace('frm_form_field', 'frm_form_field frm_conf_field', $conf_html);
                 //Remove label if stacked. Hide if inline.
                 if ($field['conf_field'] == 'inline') {
                     $conf_html = str_replace('frm_form_field', 'frm_form_field frm_hidden_container', $conf_html);
                 } else {
                     $conf_html = str_replace('frm_form_field', 'frm_form_field frm_none_container', $conf_html);
                 }
                 $html .= $conf_html;
             }
         }
     }
     if (strpos($html, '[collapse_this]')) {
         $html = str_replace('[collapse_this]', '', $html);
     }
     return $html;
 }
示例#2
0
 public static function validate_check_confirmation_field(&$errors, $field, $value, $args)
 {
     $conf_val = '';
     // Temporarily swtich $field->id in order to get and set the value posted in confirmation field
     $field_id = $field->id;
     $field->id = 'conf_' . $field_id;
     FrmEntriesHelper::get_posted_value($field, $conf_val, $args);
     // Switch $field->id back to original id
     $field->id = $field_id;
     unset($field_id);
     //If editing entry or if user hits Next/Submit on a draft
     if ($args['action'] == 'update') {
         //If in repeating section
         if (isset($args['key_pointer']) && ($args['key_pointer'] || $args['key_pointer'] === 0)) {
             $entry_id = str_replace('i', '', $args['key_pointer']);
         } else {
             $entry_id = $_POST && isset($_POST['id']) ? $_POST['id'] : false;
         }
         $prev_value = FrmEntryMeta::get_entry_meta_by_field($entry_id, $field->id);
         if ($prev_value != $value && $conf_val != $value) {
             $errors['conf_field' . $field->temp_id] = isset($field->field_options['conf_msg']) ? $field->field_options['conf_msg'] : __('The entered values do not match', 'formidable');
             $errors['field' . $field->temp_id] = '';
         }
     } else {
         if ($args['action'] == 'create' && $conf_val != $value) {
             //If creating entry
             $errors['conf_field' . $field->temp_id] = isset($field->field_options['conf_msg']) ? $field->field_options['conf_msg'] : __('The entered values do not match', 'formidable');
             $errors['field' . $field->temp_id] = '';
         }
     }
 }