/** * Define the data to be displayed within the KBS Forms post custom columns. * * @since 1.0 * @param str $column_name The name of the current column for which data should be displayed. * @param int $post_id The ID of the current post for which data is being displayed. * @return str */ function kbs_set_kbs_form_column_data($column_name, $post_id) { $kbs_form = new KBS_Form($post_id); switch ($column_name) { case 'fields': echo count($kbs_form->get_fields()); break; case 'shortcode': echo '<code>' . $kbs_form->get_shortcode() . '</code>'; break; case 'submissions': echo $kbs_form->get_submission_count(); break; } }
/** * Retrieve all form fields. * * @since 1.0 * @param int $form_id Post ID. * @param arr $args Arguments. See $defaults / WP_Query. * @return obj WP_Query Object. */ function kbs_get_fields($form_id) { $form = new KBS_Form($form_id); return $form->get_fields(); }
/** * Validate a ticket submission form. * * @since 1.0 * @return void */ function kbs_ajax_validate_form_submission() { $form = new KBS_Form($_POST['kbs_form_id']); $error = false; $agree_to_terms = kbs_get_option('show_agree_to_terms', false); foreach ($form->get_fields() as $field) { $settings = $form->get_field_settings($field->ID); if (!empty($settings['required']) && empty($_POST[$field->post_name])) { $error = kbs_form_submission_errors($field->ID, 'required'); $field = $field->post_name; } elseif ('email' == $settings['type'] || 'customer_email' == $settings['mapping']) { if (!is_email($_POST[$field->post_name])) { $error = kbs_form_submission_errors($field->ID, 'invalid_email'); $field = $field->post_name; } } if ($error) { wp_send_json(array('error' => $error, 'field' => $field)); } } if ($agree_to_terms && empty($_POST['kbs_agree_terms'])) { wp_send_json(array('error' => kbs_form_submission_errors(0, 'agree_to_terms'), 'field' => 'kbs_agree_terms')); } wp_send_json_success(array('error' => $error)); }