Handles a form submission and redirects back if conditions are met.
Description
See also
Source
File: src/db-objects/forms/form-frontend-submission-handler.php
public function maybe_handle_form_submission() { if ( ! isset( $_POST['torro_submission'] ) ) { return; } $data = wp_unslash( $_POST['torro_submission'] ); $context = $this->detect_request_form_and_submission( $data ); if ( is_wp_error( $context ) ) { // Always die when one of these strange errors happens. wp_die( $context->get_error_message(), __( 'Form Submission Error', 'torro-forms' ), 400 ); } $form = $context['form']; $submission = $context['submission']; $verified = $this->verify_request( $data, $form, $submission ); if ( ! $verified || is_wp_error( $verified ) ) { if ( ! $verified ) { $verified = new WP_Error( 'cannot_verify_request', __( 'The request could not be verified.', 'torro-forms' ) ); } // Die only if the form error could not be set. if ( ! $this->set_form_error( $form, $verified ) ) { wp_die( $verified->get_error_message(), __( 'Form Submission Error', 'torro-forms' ), 403 ); } } else { if ( ! $submission ) { $submission = $this->create_new_submission( $form, $data ); } $this->handle_form_submission( $form, $submission, $data ); } $redirect_url = ! empty( $data['original_form_id'] ) ? get_permalink( absint( $data['original_form_id'] ) ) : get_permalink( $form->id ); /** * Filters the URL to redirect the user to after a form submission request has been processed. * * If a submission is applicable, its query variable will be appended. * * @since 1.0.0 * * @param string $redirect_url URL to redirect to. Default is the original form URL. * @param Form $form Form object. */ $redirect_url = apply_filters( "{$this->form_manager->get_prefix()}handle_form_submission_redirect_url", $redirect_url, $form ); // Append submission ID if the URL belongs to the site. if ( $submission && ! empty( $submission->id ) && 0 === strpos( $redirect_url, home_url() ) ) { $redirect_url = add_query_arg( 'torro_submission_id', $submission->id, $redirect_url ); } wp_redirect( $redirect_url ); exit; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |