function pcud_form_shortcode($atts, $content = null) { require_once PC_DIR . '/classes/pc_form_framework.php'; $f_fw = new pc_form(); include_once PCUD_DIR . '/functions.php'; extract(shortcode_atts(array('form' => '', 'layout' => ''), $atts)); if (!filter_var($form, FILTER_VALIDATE_INT)) { return false; } // execute only if pvtContent or WP user is logged $pc_logged = pc_user_logged(false); if (!$pc_logged && !current_user_can(get_option('pg_min_role', 'upload_files'))) { return false; } // ignore testing mode $user_id = $pc_logged ? $GLOBALS['pc_user_id'] : 0; // form structure $term = get_term_by('id', $form, 'pcud_forms'); if (empty($term)) { return false; } if (empty($term->description)) { // retrocompatibility $form_fields = (array) get_option('pcud_form_' . $form, array()); } else { $form_fields = unserialize(base64_decode($term->description)); } // layout if (empty($layout) || !in_array($layout, array('one_col', 'fluid'))) { $layout_class = 'pc_' . get_option('pg_reg_layout', 'one_col') . '_form'; } else { $layout_class = 'pc_' . $layout . '_form'; } $form = ' <form class="pc_custom_form pc_custom_form_' . $form . ' ' . $layout_class . '"> <input type="hidden" name="pcud_fid" value="' . $form . '" />'; $form .= $f_fw->form_code(pcud_v2_field_names_sanitize($form_fields), false, $user_id); $form .= ' <div class="pc_custom_form_message"></div> <input type="button" class="pc_custom_form_btn" value="' . __('Submit', 'pcud_ml') . '" /> </form>'; return str_replace(array("\r", "\n", "\t", "\v"), '', $form); }
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_handle_custom_form() { if (isset($_POST['type']) && $_POST['type'] == 'pcud_cf_submit') { require_once PC_DIR . '/classes/pc_form_framework.php'; require_once PCUD_DIR . '/functions.php'; global $wpdb, $pc_users; $f_fw = new pc_form(); $form_id = (int) $_POST['pcud_fid']; // check for logged users $pc_logged = pc_user_logged(false); if (!$pc_logged && !current_user_can(get_option('pg_min_role', 'upload_files'))) { die(json_encode(array('resp' => 'error', 'mess' => __('You must be logged to use this form', 'pcud_ml')))); } ////////// VALIDATION //////////////////////////////////// // get form structure $term = get_term_by('id', $form_id, 'pcud_forms'); if (empty($term)) { die(json_encode(array('resp' => 'error', 'mess' => __('Form not found', 'pcud_ml')))); } if (empty($term->description)) { // retrocompatibility $form_fields = (array) get_option('pcud_form_' . $form_id, array()); } else { $form_fields = unserialize(base64_decode($term->description)); } $indexes = $f_fw->generate_validator(pcud_v2_field_names_sanitize($form_fields)); $is_valid = $f_fw->validate_form($indexes, $cust_errors = array(), false, false); $fdata = $f_fw->form_data; if (!$is_valid) { $error = $f_fw->errors; } else { // check for redirects if (isset($form_fields['redirect']) && !empty($form_fields['redirect'])) { $redirect = $form_fields['redirect'] == 'custom' ? $form_fields['cust_redir'] : get_permalink($form_fields['redirect']); } else { $redirect = ''; } // if not PC user - stop here if (!$pc_logged) { die(json_encode(array('resp' => 'success', 'mess' => __('Form submitted successfully.<br/> Not logged as PrivateContent user, nothing has been saved', 'pcud_ml'), 'redirect' => $redirect))); } // update user $result = $pc_users->update_user($GLOBALS['pc_user_id'], $fdata); if (!$result) { $error = $pc_users->validation_errors; } } // results if (isset($error) && !empty($error)) { die(json_encode(array('resp' => 'error', 'mess' => $error))); } else { // if is updating password - sync also cookie if (isset($fdata['psw'])) { $encrypted = $pc_users->get_user_field($user_id, $field); setcookie('pc_user', $GLOBALS['pc_user_id'] . '|||' . $encrypted, time() + 3600 * 6, '/'); } // PCUD-ACTION - user updated its data - passes form data do_action('pcud_user_updated_data', $fdata); // success message $mess = json_encode(array('resp' => 'success', 'mess' => __('Data saved succesfully', 'pc_ml'), 'redirect' => $redirect)); die($mess); } die; // security block } }