public static function akismet($values) { _deprecated_function(__FUNCTION__, '2.0.9', 'FrmEntryValidate::akismet'); return FrmEntryValidate::akismet($values); }
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']); } }
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(); }
private static function add_validation_messages($field, array &$add_html) { if (FrmField::is_required($field)) { $required_message = FrmFieldsHelper::get_error_msg($field, 'blank'); $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr($required_message) . '"'; } if (!FrmField::is_option_empty($field, 'invalid')) { $invalid_message = FrmFieldsHelper::get_error_msg($field, 'invalid'); $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr($invalid_message) . '"'; } if ($field['type'] == 'tel') { $format = FrmEntryValidate::phone_format($field); $format = substr($format, 2, -2); $key = 'pattern'; $add_html[$key] = $key . '="' . esc_attr($format) . '"'; } }
public static function validate_embedded_form(&$errors, $field, $exclude = array()) { // Check if this section is conditionally hidden before validating the nested fields self::validate_no_input_fields($errors, $field); $subforms = array(); FrmProFieldsHelper::get_subform_ids($subforms, $field); if (empty($subforms)) { return; } $where = array('fi.form_id' => $subforms); if (!empty($exclude)) { $where['fi.type not'] = $exclude; } $subfields = FrmField::getAll($where, 'field_order'); unset($where); foreach ($subfields as $subfield) { if (isset($_POST['item_meta'][$field->id]) && !empty($_POST['item_meta'][$field->id])) { foreach ($_POST['item_meta'][$field->id] as $k => $values) { if (!empty($k) && in_array($k, array('form', 'id'))) { continue; } FrmEntryValidate::validate_field($subfield, $errors, isset($values[$subfield->id]) ? $values[$subfield->id] : '', array('parent_field_id' => $field->id, 'key_pointer' => $k, 'id' => $subfield->id . '-' . $field->id . '-' . $k)); unset($k, $values); } } else { // TODO: do something if nothing was submitted } } }