function pc_reg_form_builder() { if (!isset($_POST['pc_nonce']) || !wp_verify_nonce($_POST['pc_nonce'], 'lcwp_ajax')) { die('Cheating?'); } include_once PC_DIR . '/classes/pc_form_framework.php'; $f_fw = new pc_form(); $form_id = trim(addslashes($_POST['form_id'])); if (!filter_var($form_id, FILTER_VALIDATE_INT)) { die('Invalid form ID'); } $term = get_term($form_id, 'pc_reg_form'); $structure = unserialize(base64_decode($term->description)); echo ' <table id="pc_rf_add_f_table" class="widefat pc_table"> <tbody> <tr> <td class="pc_label_td">' . __('Form name', 'pc_ml') . '</td> <td class="pc_field_td"> <input type="text" name="pc_rf_name" id="pc_rf_name" value="' . $term->name . '" placeholder="' . __("New form's name", 'pc_ml') . '" autocomplete="off" /> </td> </tr> <tr> <td class="pc_label_td"><input type="button" name="pc_rf_add_field" id="pc_rf_add_field" class="button-secondary" value="' . __('Add field', 'pc_ml') . '" /></td> <td class="pc_field_td"> <select name="pc_rf_fields_dd" class="lcweb-chosen pc_rf_fields_dd" data-placeholder="' . __('Add fields', 'pc_ml') . ' .." autocomplete="off">'; foreach ($f_fw->fields as $index => $data) { if (in_array($index, array('username', 'psw', 'pc_disclaimer'))) { continue; } echo '<option value="' . $index . '">' . $data['label'] . '</option>'; } echo ' <option value="custom|||text">' . __('TEXT BLOCK', 'pc_ml') . '</option> </select> </td> </tr> </tbody> </table> <table id="pc_rf_builder_table" class="widefat pc_table"> <thead> <tr> <th style="width: 15px;"></th> <th style="width: 15px;"></th> <th>' . __('Field', 'pc_ml') . '</th> <th>' . __('Required?', 'pc_ml') . '</th> </tr> </thead> <tbody>'; $txt_id = 0; foreach ($structure['include'] as $field) { $required = in_array($field, (array) $structure['require']) || in_array($field, array('username', 'psw', 'categories')) ? 'checked="checked"' : ''; $disabled = in_array($field, array('username', 'psw', 'categories')) ? 'disabled="disabled"' : ''; $del_code = in_array($field, array('username', 'psw')) ? '' : '<span class="pc_del_field" title="' . __('remove field', 'pc_ml') . '"></span>'; // text block part if ($field == 'custom|||text') { $content = isset($structure['texts']) && is_array($structure['texts']) && isset($structure['texts'][$txt_id]) ? $structure['texts'][$txt_id] : ''; $code = ' <td colspan="2"> <input type="hidden" name="pc_reg_form_field[]" value="' . $field . '" class="pc_reg_form_builder_included" /> <textarea name="pc_reg_form_texts[]" placeholder="' . __('Supports HTML and shortcodes', 'pc_ml') . '">' . $content . '</textarea> </td>'; $txt_id++; } else { $code = ' <td> <input type="hidden" name="pc_reg_form_field[]" value="' . $field . '" class="pc_reg_form_builder_included" /> ' . $f_fw->get_field_name($field) . ' </td> <td> <input type="checkbox" name="pc_reg_form_req[]" value="' . $field . '" ' . $required . ' ' . $disabled . ' class="ip_checks pc_reg_form_builder_required" autocomplete="off" /> </td>'; } echo ' <tr rel="' . $field . '"> <td>' . $del_code . '</td> <td><span class="pc_move_field" title="' . __('sort field', 'pc_ml') . '"></span></td> ' . $code . ' </tr>'; } echo '</tbody> </table>'; die; }