public static function process_entry($errors = '', $ajax = false)
 {
     $form_id = FrmAppHelper::get_post_param('form_id', '', 'absint');
     if (FrmAppHelper::is_admin() || empty($_POST) || empty($form_id) || !isset($_POST['item_key'])) {
         return;
     }
     global $frm_vars;
     $form = FrmForm::getOne($form_id);
     if (!$form) {
         return;
     }
     $params = FrmForm::get_params($form);
     if (!isset($frm_vars['form_params'])) {
         $frm_vars['form_params'] = array();
     }
     $frm_vars['form_params'][$form->id] = $params;
     if (isset($frm_vars['created_entries'][$form_id])) {
         return;
     }
     if ($errors == '') {
         $errors = FrmEntryValidate::validate($_POST);
     }
     /**
      * Use this filter to add trigger actions and add errors after
      * all other errors have been processed
      * @since 2.0.6
      */
     $errors = apply_filters('frm_entries_before_create', $errors, $form);
     $frm_vars['created_entries'][$form_id] = array('errors' => $errors);
     if (empty($errors)) {
         $_POST['frm_skip_cookie'] = 1;
         if ($params['action'] == 'create') {
             if (apply_filters('frm_continue_to_create', true, $form_id) && !isset($frm_vars['created_entries'][$form_id]['entry_id'])) {
                 $frm_vars['created_entries'][$form_id]['entry_id'] = FrmEntry::create($_POST);
             }
         }
         do_action('frm_process_entry', $params, $errors, $form, array('ajax' => $ajax));
         unset($_POST['frm_skip_cookie']);
     }
 }
Exemplo n.º 2
0
 public static function validate($values, $exclude = false)
 {
     _deprecated_function(__FUNCTION__, '2.0.9', 'FrmEntryValidate::validate');
     return FrmEntryValidate::validate($values, $exclude);
 }
 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();
 }