Пример #1
0
 protected function _get_form_acition_options()
 {
     $actions = dhvc_form_get_actions();
     $options = array('');
     foreach ($actions as $action) {
         $options[$action] = ucfirst($action);
     }
     return $options;
 }
Пример #2
0
 public function processor($is_ajax = false)
 {
     global $dhvc_form_messages;
     if ($_REQUEST['dhvc_form']) {
         // Strip slashes from the submitted data (WP adds them automatically)
         $_POST = stripslashes_deep($_POST);
         $_REQUEST = stripslashes_deep($_REQUEST);
         $_GET = stripslashes_deep($_GET);
         $nonce = $_REQUEST['_dhvc_form_nonce'];
         $form_id = $_REQUEST['dhvc_form'];
         $key = md5('dhvc_form_' . $form_id);
         $_SESSION[$key] = null;
         unset($_SESSION[$key]);
         $result = wp_verify_nonce($nonce, 'dhvc-form-' . $form_id);
         if (false != $result && get_post_meta($form_id, '_action_type', true) === 'default') {
             //processor
             do_action('dhvc_form_before_processor', $form_id);
             $_on_success = get_post_meta($form_id, '_on_success', true);
             $_form_control = get_post_meta($form_id, '_form_control', true);
             $default_action = dhvc_form_get_actions();
             $additional_setting = get_post_meta($form_id, '_additional_setting', true);
             $additional_setting = dhvc_form_additional_setting('on_sent_ok', $additional_setting, false);
             $additional_setting = apply_filters('dhvc_form_on_sent_ok', $additional_setting);
             if (isset($_REQUEST['_dhvc_form_action']) && in_array($_REQUEST['_dhvc_form_action'], $default_action)) {
                 $action = '_' . $_REQUEST['_dhvc_form_action'];
                 if (method_exists($this, $action)) {
                     $ajax_result = array();
                     if (!empty($additional_setting)) {
                         $ajax_result['scripts_on_sent_ok'] = array_map('dhvc_form_strip_quote', $additional_setting);
                     }
                     $ajax_result['on_success'] = $_on_success;
                     $ajax_result['redirect_url'] = '';
                     $result = $this->{$action}($_REQUEST);
                     if (!$is_ajax) {
                         $_SESSION[$key] = $result['message'];
                     }
                     $ajax_result['message'] = $result['message'];
                     $redirect_url = $_REQUEST['form_url'];
                     if ($result['success']) {
                         //save form register data
                         $save_data = get_post_meta($form_id, '_save_data', true);
                         if ($_form_control && !empty($save_data) && $action == '_register') {
                             $form_controls = json_decode($_form_control);
                             $this->_form_handler($form_id, $form_controls, true, false, false);
                         }
                         //end save data
                         if ($_on_success === 'message') {
                             $redirect_url = $_REQUEST['form_url'];
                         } else {
                             $redirect_to = get_post_meta($form_id, '_redirect_to', true);
                             if ($redirect_to === 'to_url') {
                                 $redirect_url = get_post_meta($form_id, '_url', true);
                             } else {
                                 if ($redirect_to === 'to_page') {
                                     $redirect_url = get_permalink(get_post_meta($form_id, '_page', true));
                                 } else {
                                     $redirect_url = get_permalink(get_post_meta($form_id, '_post', true));
                                 }
                             }
                             $_SESSION[$key] = null;
                             unset($_SESSION[$key]);
                         }
                         $ajax_result['redirect_url'] = $redirect_url;
                         if ($is_ajax) {
                             return $ajax_result;
                         }
                         wp_redirect($redirect_url);
                         exit;
                     }
                     $ajax_result['success'] = 0;
                     if ($is_ajax) {
                         return $ajax_result;
                     }
                     return false;
                 }
             } else {
                 if ($_form_control) {
                     $form_controls = json_decode($_form_control);
                     $this->_form_handler($form_id, $form_controls);
                 }
                 do_action('dhvc_form_after_processor', $form_id);
                 $ajax_result = array();
                 $ajax_result['on_success'] = $_on_success;
                 if (!empty($additional_setting)) {
                     $ajax_result['scripts_on_sent_ok'] = array_map('dhvc_form_strip_quote', $additional_setting);
                 }
                 $key = md5('dhvc_form_' . $form_id);
                 if ($_on_success === 'message') {
                     $message = get_post_meta($form_id, '_message', true);
                     $message = dhvc_form_translate_variable($message, $posted_data);
                     $message = apply_filters('dhvc_form_success_message', $message, $form_id);
                     $ajax_result['message'] = $message;
                     //$dhvc_form_messages[$form_id] = $message;
                     if (!$is_ajax) {
                         $_SESSION[$key] = $message;
                     }
                 }
                 $redirect_url = '';
                 if ($_on_success === 'message') {
                     $redirect_url = $_REQUEST['form_url'];
                     $redirect_url .= '#dhvcform-' . $form_id;
                 } else {
                     $redirect_to = get_post_meta($form_id, '_redirect_to', true);
                     if ($redirect_to === 'to_url') {
                         $redirect_url = get_post_meta($form_id, '_redirect_url', true);
                     } else {
                         if ($redirect_to === 'to_page') {
                             $redirect_url = get_permalink(get_post_meta($form_id, '_page', true));
                         } else {
                             $redirect_url = get_permalink(get_post_meta($form_id, '_post', true));
                         }
                     }
                     $_SESSION[$key] = null;
                     unset($_SESSION[$key]);
                 }
                 $ajax_result['redirect_url'] = $redirect_url;
                 if ($is_ajax) {
                     return $ajax_result;
                 }
                 wp_redirect($redirect_url);
                 exit;
             }
         }
         //
     }
     return false;
 }
Пример #3
0
 public function loadTemplate($atts, $content = null)
 {
     global $dhvc_form;
     $output = '';
     extract(shortcode_atts(array('id' => ''), $atts));
     if (empty($id)) {
         return __('No form yet! You should add some...', DHVC_FORM);
     }
     $form = get_post($id);
     $dhvc_form = $form;
     $method = get_post_meta($form->ID, '_method', true);
     $action = '';
     $action_type = get_post_meta($form->ID, '_action_type', true);
     if ($action_type === 'external_url') {
         $action = get_post_meta($form->ID, '_action_url', true);
     }
     if ($form && $form->post_status === 'publish') {
         do_action('dhvcform_before_render_form');
         wp_enqueue_style('js_composer_front');
         wp_enqueue_style('js_composer_custom_css');
         $output .= '<div id="dhvcform-' . $form->ID . '"  class="dhvc-form-container dhvc-form-icon-pos-' . get_post_meta($form->ID, '_input_icon_position', true) . ' dhvc-form-' . get_post_meta($form->ID, '_form_layout', true) . ' dhvc-form-flat">' . "\n";
         $use_ajax = get_post_meta($form->ID, '_use_ajax', true);
         $key = md5('dhvc_form_' . $id);
         $form_msg = isset($_SESSION[$key]) && !empty($_SESSION[$key]) ? $_SESSION[$key] : '';
         $form_message = '';
         $form_message .= '<div id="dhvc_form_message_' . $form->ID . '" class="dhvc-form-message ' . (!empty($form_msg) ? '' : 'dhvc-form-hidden') . '">' . "\n";
         if (!empty($form_msg)) {
             if (!empty($form_msg)) {
                 foreach ((array) $form_msg as $msg) {
                     $form_message .= $msg;
                 }
                 //unset this form message
                 $_SESSION[$key] = null;
                 unset($_SESSION[$key]);
             }
         }
         $form_message .= '</div>' . "\n";
         if (get_post_meta($form->ID, '_message_position', true) !== 'bottom') {
             $output .= $form_message;
         }
         $output .= '<form data-popup="' . (get_post_meta($form->ID, '_form_popup', true) ? '1' : '0') . '" autocomplete="off" data-use-ajax="' . (int) $use_ajax . '" method="' . $method . '" class="dhvcform dhvcform-' . $form->ID . '" enctype="multipart/form-data"' . (!empty($action) ? ' action="' . $action . '"' : '') . '>' . "\n";
         $output .= '<div style="display: none;">' . "\n";
         if ($use_ajax) {
             $output .= '<input type="hidden" name="action" value="dhvc_form_ajax">' . "\n";
             $output .= '<input type="hidden" name="_dhvc_form_is_ajax_call" value="1">' . "\n";
         }
         if ($action_type === 'default') {
             $form_action = get_post_meta($form->ID, '_form_action', true);
             if (in_array($form_action, dhvc_form_get_actions())) {
                 $output .= '<input type="hidden" name="_dhvc_form_action" value="' . $form_action . '">' . "\n";
             }
         }
         $output .= '<input type="hidden" name="dhvc_form" value="' . $form->ID . '">' . "\n";
         $output .= '<input type="hidden" name="form_url" value="' . esc_attr(dhvc_form_get_current_url()) . '">' . "\n";
         $output .= '<input type="hidden" name="referer" value="' . esc_attr(dhvc_form_get_http_referer()) . '">' . "\n";
         $output .= '<input type="hidden" name="post_id" value="' . get_the_ID() . '">' . "\n";
         $output .= '<input type="hidden" name="_dhvc_form_nonce" value="' . wp_create_nonce('dhvc-form-' . $form->ID) . '">' . "\n";
         $output .= '</div>' . "\n";
         $output .= '<div class="dhvc-form-inner">' . "\n";
         $output .= wpb_js_remove_wpautop($form->post_content);
         $output .= '</div>';
         if (!dhvc_form_has_submit_shortcode($form->ID)) {
             $output .= '<div class="dhvc-form-action">' . "\n";
             $form_button = '<button type="submit" class="button dhvc-form-submit"><span class="dhvc-form-submit-label">' . __('Submit', DHVC_FORM) . '</span><span class="dhvc-form-submit-spinner"></span></button>';
             $form_button = apply_filters('dhvc_form_action', $form_button, $form->ID);
             $output .= $form_button . "\n";
             $output .= '</div>' . "\n";
         }
         if (get_post_meta($form->ID, '_message_position', true) === 'bottom') {
             $output .= $form_message;
         }
         $output .= '</form>' . "\n";
         $output .= '</div>' . "\n";
         $output .= $this->_edit_form_link($id);
         do_action('dhvcform_after_render_form');
         return $output;
     }
     return __('No form yet! You should add some...', DHVC_FORM);
 }