Exemple #1
0
    function cp_formbuilder($results, $post = false)
    {
        global $cp_options;
        $custom_fields_array = array();
        foreach ($results as $result) {
            // external plugins can modify or disable field
            $result = apply_filters('cp_formbuilder_field', $result, $post);
            if (!$result) {
                continue;
            }
            if (appthemes_str_starts_with($result->field_name, 'cp_')) {
                $custom_fields_array[] = $result->field_name;
            }
            $post_meta_val = $post ? get_post_meta($post->ID, $result->field_name, true) : false;
            ?>

			<li id="list_<?php 
            echo esc_attr($result->field_name);
            ?>
">
				<div class="labelwrapper">
					<label><?php 
            echo esc_html(translate($result->field_label, APP_TD));
            ?>
 <?php 
            if ($result->field_req) {
                echo '<span class="colour">(*)</span>';
            }
            ?>
</label>
				</div>

				<?php 
            $show_tooltip = !empty($result->field_tooltip);
            if ($show_tooltip) {
                echo html('a href="#" tip="' . esc_attr(translate($result->field_tooltip, APP_TD)) . '" tabindex="999"', html('div class="dashicons-before helpico"', '&nbsp;'));
            } else {
            }
            switch ($result->field_type) {
                case 'text box':
                    if (isset($_POST[$result->field_name])) {
                        $value = wp_kses_post(appthemes_clean($_POST[$result->field_name]));
                    } elseif ($result->field_name == 'post_title' && $post) {
                        $value = $post->post_title;
                    } elseif ($result->field_name == 'tags_input' && $post) {
                        $value = rtrim(trim(cp_get_the_term_list($post->ID, APP_TAX_TAG)), ',');
                    } else {
                        $value = $post_meta_val;
                    }
                    $field_class = $result->field_req ? 'text required' : 'text';
                    if ('cp_price' == $result->field_name && $cp_options->clean_price_field) {
                        $field_class .= ' number';
                    }
                    $field_minlength = empty($result->field_min_length) ? '0' : $result->field_min_length;
                    $args = array('value' => $value, 'name' => $result->field_name, 'id' => $result->field_name, 'type' => 'text', 'class' => $field_class, 'minlength' => $field_minlength);
                    $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                    echo html('input', $args);
                    break;
                case 'drop-down':
                    $options = explode(',', $result->field_values);
                    $options = array_map('trim', $options);
                    $html_options = '';
                    $html_options .= html('option', array('value' => ''), __('-- Select --', APP_TD));
                    foreach ($options as $option) {
                        $args = array('value' => $option);
                        if ($option == $post_meta_val) {
                            $args['selected'] = 'selected';
                        }
                        $args = apply_filters('cp_formbuilder_' . $result->field_name . '_option', $args, $result, $post);
                        $html_options .= html('option', $args, $option);
                    }
                    $field_class = $result->field_req ? 'dropdownlist required' : 'dropdownlist';
                    $args = array('name' => $result->field_name, 'id' => $result->field_name, 'class' => $field_class);
                    $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                    echo html('select', $args, $html_options);
                    break;
                case 'text area':
                    if (isset($_POST[$result->field_name])) {
                        $value = wp_kses_post(appthemes_clean($_POST[$result->field_name]));
                    } elseif ($result->field_name == 'post_content' && $post) {
                        $value = $post->post_content;
                    } else {
                        $value = $post_meta_val;
                    }
                    $field_class = $result->field_req ? 'required' : '';
                    $field_minlength = empty($result->field_min_length) ? '15' : $result->field_min_length;
                    $args = array('value' => $value, 'name' => $result->field_name, 'id' => $result->field_name, 'rows' => '8', 'cols' => '40', 'class' => $field_class, 'minlength' => $field_minlength);
                    $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                    $value = $args['value'];
                    unset($args['value']);
                    if ($cp_options->allow_html && !wp_is_mobile()) {
                        cp_editor($value, $args);
                    } else {
                        echo html('textarea', $args, esc_textarea($value));
                    }
                    break;
                case 'radio':
                    $options = explode(',', $result->field_values);
                    $options = array_map('trim', $options);
                    $html_radio = '';
                    $html_options = '';
                    if (!$result->field_req) {
                        $args = array('value' => '', 'type' => 'radio', 'class' => 'radiolist', 'name' => $result->field_name, 'id' => $result->field_name);
                        if (empty($post_meta_val)) {
                            $args['checked'] = 'checked';
                        }
                        $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                        $html_radio = html('input', $args) . '&nbsp;&nbsp;' . __('None', APP_TD);
                        $html_options .= html('li', array(), $html_radio);
                    }
                    foreach ($options as $option) {
                        $field_class = $result->field_req ? 'radiolist required' : 'radiolist';
                        $args = array('value' => $option, 'type' => 'radio', 'class' => $field_class, 'name' => $result->field_name, 'id' => $result->field_name);
                        if ($option == $post_meta_val) {
                            $args['checked'] = 'checked';
                        }
                        $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                        $html_radio = html('input', $args) . '&nbsp;&nbsp;' . $option;
                        $html_options .= html('li', array(), $html_radio);
                    }
                    echo html('ol', array('class' => 'radios'), $html_options);
                    break;
                case 'checkbox':
                    $post_meta_val = $post ? get_post_meta($post->ID, $result->field_name, false) : array();
                    $options = explode(',', $result->field_values);
                    $options = array_map('trim', $options);
                    $optionCursor = 1;
                    $html_checkbox = '';
                    $html_options = '';
                    foreach ($options as $option) {
                        $field_class = $result->field_req ? 'checkboxlist required' : 'checkboxlist';
                        $args = array('value' => $option, 'type' => 'checkbox', 'class' => $field_class, 'name' => $result->field_name . '[]', 'id' => $result->field_name . '_' . $optionCursor++);
                        if (in_array($option, $post_meta_val)) {
                            $args['checked'] = 'checked';
                        }
                        $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                        $html_checkbox = html('input', $args) . '&nbsp;&nbsp;' . $option;
                        $html_options .= html('li', array(), $html_checkbox);
                    }
                    echo html('ol', array('class' => 'checkboxes'), $html_options);
                    break;
            }
            ?>

			</li>
	<?php 
            echo html('div', array('class' => 'clr'));
        }
        // put all the custom field names into an hidden field so we can process them on save
        $custom_fields_vals = implode(',', $custom_fields_array);
        echo html('input', array('type' => 'hidden', 'name' => 'custom_fields_vals', 'value' => $custom_fields_vals));
        cp_action_formbuilder($results, $post);
    }
    function cp_formbuilder_buyer($results, $post = false)
    {
        global $wpdb, $cp_options;
        $custom_fields_array = array();
        foreach ($results as $result) {
            // external plugins can modify or disable field
            $result = apply_filters('cp_formbuilder_field', $result, $post);
            //
            //var_dump($result);
            if (!$result) {
                continue;
            }
            if (appthemes_str_starts_with($result->field_name, 'cp_')) {
                $custom_fields_array[] = $result->field_name;
            }
            $post_meta_val = $post ? get_post_meta($post->ID, $result->field_name, true) : false;
            if ($result->field_name == 'post_content') {
                echo "</ol><ol>";
            }
            ?>

			<li id="list_<?php 
            echo esc_attr($result->field_name);
            ?>
" <?php 
            /*if($result->field_name=='post_title') echo 'style="display:none;"'; */
            ?>
>
				<?php 
            /*?><div class="labelwrapper">
            			<label><?php if ( $result->field_tooltip ) { ?><a href="#" tip="<?php echo esc_attr( translate( $result->field_tooltip, APP_TD ) ); ?>" tabindex="999"><div class="helpico"></div></a><?php } ?><?php echo esc_html( translate( $result->field_label, APP_TD ) ); ?>: <?php if ( $result->field_req ) echo '<span class="colour">*</span>'; ?></label>
            			<?php if ( ($result->field_type) == 'text area' && ( $cp_options->allow_html ) ) { // only show this for tinymce since it's hard to position the error otherwise ?>
            				<br /><label class="invalid tinymce" for="<?php echo esc_attr($result->field_name); ?>"><?php _e( 'This field is required.', APP_TD ); ?></label>
            			<?php } ?>
            		</div><?php */
            ?>
				<?php 
            if ($result->field_name == 'cp_video_url') {
                continue;
            }
            switch ($result->field_type) {
                case 'text box':
                    if (isset($_POST[$result->field_name])) {
                        $value = wp_kses_post(appthemes_clean($_POST[$result->field_name]));
                    } elseif ($result->field_name == 'post_title' && $post) {
                        $value = $post->post_title;
                    } elseif ($result->field_name == 'tags_input' && $post) {
                        $value = rtrim(trim(cp_get_the_term_list($post->ID, APP_TAX_TAG)), ',');
                    } else {
                        $value = $post_meta_val;
                    }
                    if ($result->field_name == 'cp_price') {
                        //echo html( 'input', $args );
                        echo '<label class="form-sub-label" for="first_3" id="sublabel_first" style="color:#fff;">Maximum Budget </label><br>';
                    }
                    $field_class = $result->field_req ? 'text required' : 'text';
                    $field_minlength = empty($result->field_min_length) ? '2' : $result->field_min_length;
                    $args = array('value' => $value, 'name' => $result->field_name, 'id' => $result->field_name, 'type' => 'text', 'class' => $field_class, 'minlength' => $field_minlength, 'placeholder' => $result->field_label);
                    $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                    echo html('input', $args);
                    echo html('div', array('class' => 'clr'));
                    break;
                case 'drop-down':
                case 'multiple-drop-down':
                    $options = explode(',', $result->field_values);
                    $options = array_map('trim', $options);
                    $html_options = '';
                    if ($result->field_type == 'multiple-drop-down') {
                        echo '<label class="form-sub-label mobileonly" for="first_3" id="sublabel_first" style="color:#fff;">' . $result->field_label . '</label><br>';
                    }
                    $html_options .= html('option', array('value' => ''), __($result->field_label, APP_TD));
                    foreach ($options as $option) {
                        $args = array('value' => $option);
                        if ($option == $post_meta_val) {
                            $args['selected'] = 'selected';
                        }
                        $args = apply_filters('cp_formbuilder_' . $result->field_name . '_option', $args, $result, $post);
                        $html_options .= html('option', $args, $option);
                    }
                    $field_class = $result->field_req ? 'dropdownlist required' : 'dropdownlist';
                    if ($result->field_type == 'multiple-drop-down') {
                        $args = array('name' => $result->field_name . '[]', 'id' => $result->field_name . '[]', 'class' => $field_class, 'multiple' => "multiple");
                    } elseif ($result->field_type == 'drop-down' && $result->field_name == 'cp_age') {
                        echo '<label class="form-sub-label mobileonly" for="first_3" id="sublabel_first" style="color:#fff;">' . $result->field_label . '</label><br>';
                        $args = array('name' => $result->field_name . '[]', 'id' => $result->field_name . '[]', 'class' => $field_class, 'multiple' => "multiple");
                    } elseif ($result->field_type == 'drop-down' && $result->field_name == 'cp_color') {
                        echo '<label class="form-sub-label mobileonly" for="first_3" id="sublabel_first" style="color:#fff;">' . $result->field_label . '</label><br>';
                        $args = array('name' => $result->field_name . '[]', 'id' => $result->field_name . '[]', 'class' => $field_class, 'multiple' => "multiple");
                    } elseif ($result->field_type == 'drop-down' && $result->field_name == 'cp_state') {
                        echo '<label class="form-sub-label mobileonly" for="first_3" id="sublabel_first" style="color:#fff;">' . $result->field_label . '</label><br>';
                        $args = array('name' => $result->field_name . '[]', 'id' => $result->field_name . '[]', 'class' => $field_class, 'multiple' => "multiple");
                    } else {
                        $args = array('name' => $result->field_name, 'id' => $result->field_name, 'class' => $field_class);
                    }
                    $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                    echo html('select', $args, $html_options);
                    echo html('div', array('class' => 'clr'));
                    break;
                case 'text area':
                    if (isset($_POST[$result->field_name])) {
                        $value = wp_kses_post(appthemes_clean($_POST[$result->field_name]));
                    } elseif ($result->field_name == 'post_content' && $post) {
                        $value = $post->post_content;
                    } else {
                        $value = $post_meta_val;
                    }
                    $field_class = $result->field_req ? 'required' : '';
                    $field_minlength = empty($result->field_min_length) ? '2' : $result->field_min_length;
                    $args = array('value' => $value, 'name' => $result->field_name, 'id' => $result->field_name, 'rows' => '8', 'cols' => '40', 'class' => $field_class, 'minlength' => $field_minlength, 'placeholder' => $result->field_label);
                    $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                    $value = $args['value'];
                    unset($args['value']);
                    echo html('div', array('class' => 'clr'));
                    echo html('textarea', $args, esc_textarea($value));
                    echo html('div', array('class' => 'clr'));
                    ?>

							<?php 
                    if ($cp_options->allow_html && !wp_is_mobile()) {
                        ?>
								<script type="text/javascript"> <!--
								tinyMCE.execCommand('mceAddControl', false, '<?php 
                        echo esc_attr($result->field_name);
                        ?>
');
								--></script>
							<?php 
                    }
                    ?>

					<?php 
                    break;
                case 'radio':
                    $options = explode(',', $result->field_values);
                    $options = array_map('trim', $options);
                    $html_radio = '';
                    $html_options = '';
                    if (!$result->field_req) {
                        $args = array('value' => '', 'type' => 'radio', 'class' => 'radiolist', 'name' => $result->field_name, 'id' => $result->field_name);
                        if (empty($post_meta_val)) {
                            $args['checked'] = 'checked';
                        }
                        $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                        $html_radio = html('input', $args) . '&nbsp;&nbsp;' . __('None', APP_TD);
                        $html_options .= html('li', array(), $html_radio);
                    }
                    foreach ($options as $option) {
                        $field_class = $result->field_req ? 'radiolist required' : 'radiolist';
                        $args = array('value' => $option, 'type' => 'radio', 'class' => $field_class, 'name' => $result->field_name, 'id' => $result->field_name);
                        if ($option == $post_meta_val) {
                            $args['checked'] = 'checked';
                        }
                        $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                        $html_radio = html('input', $args) . '&nbsp;&nbsp;' . $option;
                        $html_options .= html('li', array(), $html_radio);
                    }
                    echo html('ol', array('class' => 'radios'), $html_options);
                    echo html('div', array('class' => 'clr'));
                    break;
                case 'checkbox':
                    $post_meta_val = $post ? get_post_meta($post->ID, $result->field_name, false) : array();
                    $options = explode(',', $result->field_values);
                    $options = array_map('trim', $options);
                    $optionCursor = 1;
                    $html_checkbox = '';
                    $html_options = '';
                    foreach ($options as $option) {
                        $field_class = $result->field_req ? 'checkboxlist required' : 'checkboxlist';
                        $args = array('value' => $option, 'type' => 'checkbox', 'class' => $field_class, 'name' => $result->field_name . '[]', 'id' => $result->field_name . '_' . $optionCursor++);
                        if (in_array($option, $post_meta_val)) {
                            $args['checked'] = 'checked';
                        }
                        $args = apply_filters('cp_formbuilder_' . $result->field_name, $args, $result, $post);
                        $html_checkbox = html('input', $args) . '&nbsp;&nbsp;' . $option;
                        $html_options .= html('li', array(), $html_checkbox);
                    }
                    echo html('ol', array('class' => 'checkboxes'), $html_options);
                    echo html('div', array('class' => 'clr'));
                    break;
            }
            ?>

			</li>

	<?php 
        }
        // put all the custom field names into an hidden field so we can process them on save
        //$custom_fields_vals['cp_type'
        //var_dump($custom_fields_array);
        $custom_fields_array[] = 'cp_type';
        //var_dump($custom_fields_array);
        //exit;
        $custom_fields_vals = implode(',', $custom_fields_array);
        echo html('input', array('type' => 'hidden', 'name' => 'custom_fields_vals', 'value' => $custom_fields_vals));
        cp_action_formbuilder($results, $post);
    }