function pcud_form_builder() { require_once PCUD_DIR . '/functions.php'; require_once PC_DIR . '/classes/pc_form_framework.php'; if (!isset($_POST['form_id'])) { die('data is missing'); } $form_id = addslashes($_POST['form_id']); // get all the fields $f_fw = new pc_form(); // retrieve form term $term = get_term_by('id', $form_id, 'pcud_forms'); if (!$term) { die('form not found'); } // field selector ?> <h3><?php echo $term->name; ?> </h3> <div id="pcud_form_builder_top" class="postbox"> <h3 class="hndle"><?php _e('Add Form Fields', 'pcud_ml'); ?> </h3> <div class="inside"> <div> <table class="widefat pc_table"> <tr> <td class="pc_label_td"><?php _e('Select field', 'pcud_ml'); ?> </td> <td class="pc_field_td"> <select data-placeholder="<?php _e('Select field', 'pcud_ml'); ?> .." name="pcud_fields_list" id="pcud_fields_list" class="lcweb-chosen" autocomplete="off" style="width: 400px;"> <?php foreach ($f_fw->fields as $field => $data) { if (!in_array($field, array_merge(pcud_wizards_ignore_fields(), array('username')))) { echo '<option value="' . $field . '">' . $data['label'] . '</option>'; } } ?> <option value="custom|||text"><?php _e('TEXT BLOCK', 'pc_ml'); ?> </option> </select> </td> <td> <div id="add_field_btn"> <input type="button" name="add_field" value="<?php _e('Add', 'pcud_ml'); ?> " class="button-secondary" /> <div style="width: 30px; padding-left: 7px; float: right;"></div> </div> </td> </tr> </table> <div> </div> </div> </div> </div> <?php // get form fields if (empty($term->description)) { // retrocompatibility $form_fields = (array) get_option('pcud_form_' . $form_id, array()); } else { $form_fields = unserialize(base64_decode($term->description)); } ?> <h3><?php _e('Form Structure', 'pcud_ml'); ?> </h3> <table id="pcud_form_table" class="widefat pc_table"> <thead> <tr> <th style="width: 15px;"></th> <th style="width: 15px;"></th> <th style="padding-left: 15px;"><?php _e('Field name', 'pcud_ml'); ?> </th> <th><?php _e('Required?', 'pcud_ml'); ?> </th> </tr> </thead> <tbody> <?php if (!empty($form_fields)) { $form_fields = pcud_v2_field_names_sanitize($form_fields); $incl = (array) $form_fields['include']; $req = (array) $form_fields['require']; $texts = isset($form_fields['texts']) ? (array) $form_fields['texts'] : array(); $txt_id = 0; foreach ($incl as $f_name) { if ($f_name == 'custom|||text' && isset($texts[$txt_id])) { echo ' <tr rel="' . $field . '"> <td><span class="pc_del_field"></span></td> <td><span class="pc_move_field"></span></td> <td colspan="2"> <input type="hidden" name="pcud_include_field[]" value="' . $field . '" class="pcud_incl_f" /> <textarea name="pcud_form_texts[]" placeholder="' . __('Supports HTML and shortcodes', 'pc_ml') . '">' . $texts[$txt_id] . '</textarea> </td> </tr>'; $txt_id++; } else { if (isset($f_fw->fields[$f_name])) { $field_data = $f_fw->fields[$f_name]; $sel = in_array($f_name, $req) ? 'checked="checked"' : ''; // if password or required email disable "required" switch if ($f_name == 'psw' || $f_name == 'email' && $f_fw->mail_is_required) { $dis_check = 'disabled="disabled"'; $sel = 'checked="checked"'; } else { $dis_check = ''; } echo ' <tr rel="' . $f_name . '"> <td><span class="pc_del_field"></span></td> <td><span class="pc_move_field"></span></td> <td style="padding-left: 15px;"> <input type="hidden" name="pcud_include_field[]" value="' . $f_name . '" class="pcud_incl_f" /> <span>' . $field_data['label'] . '</span> </td> <td><input type="checkbox" name="pcud_require_field[]" value="' . $f_name . '" ' . $sel . ' ' . $dis_check . ' class="pcud_req_f ip_checks" /></td> </tr> '; } } } } ?> </tbody> </table> <?php // form redirect $redirect = is_array($form_fields) && isset($form_fields['redirect']) ? $form_fields['redirect'] : ''; // custom redirect $custom_red = $redirect == 'custom' ? $form_fields['cust_redir'] : ''; // pages list $pages = get_pages(); ?> <h3><?php _e('Form Redirect', 'pcud_ml'); ?> </h3> <table id="pcud_form_table" class="widefat pc_table"> </tbody> <tr> <td class="pc_label_td" rowspan="2"><?php _e("Redirect target", 'pcud_ml'); ?> </td> <td class="pc_field_td"> <select name="pcud_redirect" id="pcud_redirect" class="lcweb-chosen" data-placeholder="<?php _e('Select a page', 'pcud_ml'); ?> .." autocomplete="off"> <option value=""><?php _e('No redirect', 'pcud_ml'); ?> </option> <option value="custom" <?php if ($redirect == 'custom') { echo 'selected="selected"'; } ?> ><?php _e('Custom redirect', 'pcud_ml'); ?> </option> <?php foreach ($pages as $pag) { $selected = $redirect == $pag->ID ? 'selected="selected"' : ''; echo '<option value="' . $pag->ID . '" ' . $selected . '>' . $pag->post_title . '</option>'; } ?> </select> </td> <td><span class="info"><?php _e('Redirect target after successful form submission', 'pcud_ml'); ?> </span></td> </tr> <tr id="pcud_cust_redir_wrap"> <td colspan="2" <?php if ($redirect != 'custom') { echo 'style="display: none;"'; } ?> > <input type="text" name="pcud_cust_redir" value="<?php echo pc_sanitize_input($custom_red); ?> " autocomplete="off" placeholder="<?php _e('insert a valid URL', 'pcud_ml'); ?> " style="width: 100%;" /> </td> </tr> </tbody> </table> <?php die; }
function pcud_sw_contents() { include_once PCUD_DIR . '/functions.php'; include_once PC_DIR . '/classes/pc_form_framework.php'; $f_fw = new pc_form(); // get forms $forms = get_terms('pcud_forms', 'hide_empty=0'); $form_fields = $f_fw->fields; ?> <div id="pcud_sc_wizard"> <table class="form-table pc_tinymce_table"> <tr> <td style="padding-right: 0;"><?php _e('User data to display', 'pcud_ml'); ?> </td> <td> <select name="pcud_fields_list" id="pcud_fields_list" class="lcweb-chosen f_type" data-placeholder="<?php _e('Select field', 'pcud_ml'); ?> .." autocomplete="off"> <?php foreach ($form_fields as $field_id => $data) { if (!in_array($field_id, pcud_wizards_ignore_fields(true))) { echo '<option value="' . $field_id . '">' . $data['label'] . '</option>'; } } ?> </select> </td> <td><input type="button" id="pcud-user-data-submit" class="button-primary" value="<?php _e('Insert', 'pcud_ml'); ?> " name="submit" /></td> </tr> <tr class="tbl_last"> <td style="padding-bottom: 0px; font-size: 15px;" colspan="2"> <strong><?php _e('Custom form', 'pcud_ml'); ?> </strong> </td> </tr> <tr> <td style="padding-right: 0;"><?php _e('Custom form to use', 'pcud_ml'); ?> </td> <td colspan="2"> <select name="pcud_form_list" id="pcud_forms_list" class="lcweb-chosen f_type" data-placeholder="<?php _e('Select form', 'pcud_ml'); ?> .." autocomplete="off"> <?php foreach ($forms as $form) { echo '<option value="' . $form->term_id . '">' . $form->name . '</option>'; } ?> </select> </td> </tr> <tr> <td><?php _e('Layout', 'pcud_ml'); ?> </td> <td> <select name="pcud_form_layout" id="pcud_forms_layout" class="lcweb-chosen f_type" data-placeholder="<?php _e('Select an option', 'pcud_ml'); ?> .." autocomplete="off"> <option value="" selected="selected"><?php _e('Default one', 'pcud_ml'); ?> </option> <option value="one_col"><?php _e('Single column', 'pcud_ml'); ?> </option> <option value="fluid"><?php _e('Fluid (multi column)', 'pcud_ml'); ?> </option> </select> </td> <td><input type="button" id="pcud-form-submit" class="button-primary" value="<?php _e('Insert form', 'pcud_ml'); ?> " name="submit" /></td> </tr> </table> <table class="form-table pc_tinymce_table" style="margin-top: 0;"> <tr class="tbl_last"> <td style="padding-bottom: 0px; font-size: 14px;" colspan="2"> <strong><?php _e('Conditional block', 'pcud_ml'); ?> </strong> </td> </tr> <tr> <td><?php _e('Show content if', 'pcud_ml'); ?> </td> <td> <select name="pcud_cb_field" id="pcud_cb_field" class="lcweb-chosen f_type" data-placeholder="<?php _e('Select field', 'pcud_ml'); ?> .." autocomplete="off"> <?php foreach ($form_fields as $field_id => $data) { if (!in_array($field_id, pcud_wizards_ignore_fields())) { echo '<option value="' . $field_id . '">' . $data['label'] . '</option>'; } } ?> </select> </td> </tr> <tr class="tbl_last"> <td> <select name="pcud_cb_condition" id="pcud_cb_condition" class="lcweb-chosen f_type" data-placeholder="'. __('Select a condition', 'pcud_ml') .' .." style="width: 140px;"> <option value="=" ><?php _e('is equal to', 'pcud_ml'); ?> </option> <option value="!=" ><?php _e('is different from', 'pcud_ml'); ?> </option> <option value="big" ><?php _e('is greater than', 'pcud_ml'); ?> </option> <option value="small" ><?php _e('is lower than', 'pcud_ml'); ?> </option> <option value="like"><?php _e('contains', 'pcud_ml'); ?> </option> </select> </td> <td> <input type="text" name="pcud_cb_val" id="pcud_cb_val" value="" autocomplete="off" /> </td> </tr> <tr class="tbl_last"> <td colspan="2"><input type="button" id="pcud_cb_submit" class="button-primary" value="<?php _e('Insert block', 'pcud_ml'); ?> " name="submit" /></td> </tr> </table> <script type="text/javascript"> jQuery(document).ready(function(e) { // [pcud-user-data] jQuery('body').delegate("#pcud-user-data-submit", "click", function() { var fid = jQuery("#pcud_fields_list").val(); if(fid != "") { var shortcode = '[pcud-user-data f="'+fid+'"]'; tinyMCE.activeEditor.execCommand("mceInsertContent", 0, shortcode); tb_remove(); } }); // [pcud-form] jQuery('body').delegate("#pcud-form-submit", "click", function() { var fid = jQuery("#pcud_forms_list").val(); if(fid != "") { // layout if(jQuery('#pcud_forms_layout').val()) { var f_layout = ' layout="'+ jQuery('#pcud_forms_layout').val() +'" '; } else {var f_layout = '';} var shortcode = '[pcud-form form="'+fid+'"'+f_layout+']'; tinyMCE.activeEditor.execCommand("mceInsertContent", 0, shortcode); tb_remove(); } }); // [pcud-cond-block] jQuery('body').delegate("#pcud_cb_submit", "click", function() { var fid = jQuery("#pcud_cb_field").val(); var cond = jQuery("#pcud_cb_condition").val(); var val = jQuery("#pcud_cb_val").val(); val = val.replace(/"/g, '"'); if(fid != "") { var shortcode = '[pcud-cond-block f="'+ fid +'" cond="'+ cond +'" val="'+ val +'"][/pcud-cond-block]'; tinyMCE.activeEditor.execCommand("mceInsertContent", 0, shortcode); tb_remove(); } }); }); </script> </div> <?php }