Sets a form error so that it can be printed to the user in the next request.
Description
See also
Parameters
- $form
-
(awsmug\Torro_Forms\DB_Objects\Forms\Form) (Required) Form object.
- $error
-
(WP_Error) (Required) Error object.
Return
(bool) True on success, false on failure.
Source
File: src/db-objects/forms/form-frontend-submission-handler.php
protected function set_form_error( $form, $error ) { $key = $this->form_manager->get_prefix() . 'form_errors'; if ( is_user_logged_in() ) { $errors = get_user_meta( get_current_user_id(), $key, true ); if ( ! is_array( $errors ) ) { $errors = array(); } $errors[ $form->id ] = $error->get_error_message(); return (bool) update_user_meta( get_current_user_id(), $key, $errors ); } if ( ! isset( $_SESSION ) ) { if ( headers_sent() ) { return false; } session_start(); } if ( ! isset( $_SESSION[ $key ] ) ) { $_SESSION[ $key ] = array(); } $_SESSION[ $key ][ $form->id ] = $error->get_error_message(); return true; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |