public static function ajax_create()
 {
     if (!FrmAppHelper::doing_ajax() || !isset($_POST['form_id'])) {
         // normally, this function would be triggered with the wp_ajax hook, but we need it fired sooner
         return;
     }
     $allowed_actions = array('frm_entries_create', 'frm_entries_update');
     if (!in_array(FrmAppHelper::get_post_param('action', '', 'sanitize_title'), $allowed_actions)) {
         // allow ajax creating and updating
         return;
     }
     $form = FrmForm::getOne((int) $_POST['form_id']);
     if (!$form) {
         echo false;
         wp_die();
     }
     $no_ajax_fields = array('file');
     $errors = FrmEntryValidate::validate($_POST, $no_ajax_fields);
     if (empty($errors)) {
         if (FrmProForm::is_ajax_on($form)) {
             global $frm_vars;
             $frm_vars['ajax'] = true;
             $frm_vars['css_loaded'] = true;
             // don't load scripts if we are going backwards in the form
             $going_backwards = FrmProFormsHelper::going_to_prev($form->id);
             // save the entry if there is not another page or when saving a draft
             if (!isset($_POST['frm_page_order_' . $form->id]) && !$going_backwards || FrmProFormsHelper::saving_draft()) {
                 $processed = true;
                 FrmEntriesController::process_entry($errors, true);
             }
             echo FrmFormsController::show_form($form->id);
             // trigger the footer scripts if there is a form to show
             if ($errors || !isset($processed) || !empty($frm_vars['forms_loaded'])) {
                 self::print_ajax_scripts($going_backwards ? 'none' : '');
             }
         } else {
             echo false;
         }
     } else {
         $obj = array();
         foreach ($errors as $field => $error) {
             $field_id = str_replace('field', '', $field);
             $obj[$field_id] = $error;
         }
         echo json_encode($obj);
     }
     wp_die();
 }
 public static function ajax_create()
 {
     global $frm_entry;
     $frm_form = new FrmForm();
     $form = $frm_form->getOne($_POST['form_id']);
     if (!$form) {
         echo false;
         die;
     }
     $no_ajax_fields = array('file');
     $errors = $frm_entry->validate($_POST, $no_ajax_fields);
     if (empty($errors)) {
         global $wpdb;
         $where = $wpdb->prepare("form_id=%d", $form->id);
         if (isset($_POST['frm_page_order_' . $form->id])) {
             $where .= $wpdb->prepare(" AND field_order < %d", $_POST['frm_page_order_' . $form->id]);
         }
         $ajax = isset($form->options['ajax_submit']) ? $form->options['ajax_submit'] : 0;
         //ajax submit if no file, rte, captcha
         if ($ajax) {
             $no_ajax = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}frm_fields WHERE type in ('" . implode("','", $no_ajax_fields) . "') AND {$where} LIMIT 1");
             if ($no_ajax) {
                 $ajax = false;
             }
         }
         if ($ajax) {
             global $frm_vars;
             $frm_vars['ajax'] = true;
             $frm_vars['css_loaded'] = true;
             if (!isset($_POST['frm_page_order_' . $form->id]) && !FrmProFormsHelper::going_to_prev($form->id) || FrmProFormsHelper::saving_draft($form->id)) {
                 $processed = true;
                 FrmEntriesController::process_entry($errors, true);
             }
             echo FrmFormsController::show_form($form->id);
             // trigger the footer scripts if there is a form to show
             if ($errors || !isset($form->options['show_form']) || $form->options['show_form'] || !isset($processed)) {
                 self::register_scripts();
                 FrmProEntriesController::enqueue_footer_js();
                 wp_deregister_script('formidable');
                 global $wp_scripts, $wp_styles;
                 foreach (array('jquery', 'jquery-ui-core', 'jquery-migrate', 'thickbox') as $s) {
                     if (isset($wp_scripts->registered[$s])) {
                         $wp_scripts->done[] = $s;
                     }
                     unset($s);
                 }
                 $keep_styles = apply_filters('frm_ajax_load_styles', array('dashicons', 'jquery-theme'));
                 foreach ($wp_styles->registered as $s => $info) {
                     if (!is_array($keep_styles) || !in_array($s, $keep_styles)) {
                         $wp_styles->done[] = $s;
                     }
                     unset($s);
                 }
                 wp_print_footer_scripts();
                 FrmProEntriesController::footer_js();
             }
         } else {
             echo false;
         }
     } else {
         $errors = str_replace('"', '&quot;', $errors);
         $obj = array();
         foreach ($errors as $field => $error) {
             $field_id = str_replace('field', '', $field);
             $obj[$field_id] = $error;
         }
         echo json_encode($obj);
     }
     die;
 }