'invalid_nonce', 'message' => __( 'This form has expired. Please reload the page and try again.', 'devplugins-custom-form-builder' ), ), 403 ); } $form_id = Request::int( 'formpilot_form_id' ); $post_id = Request::int( 'formpilot_post_id' ); $result = $this->processor->process( $form_id, $this->submitted_values(), $this->processor->context( $post_id ) ); if ( $result instanceof WP_Error ) { $data = $result->get_error_data(); $data = is_array( $data ) ? $data : array(); wp_send_json_error( array( 'code' => $result->get_error_code(), 'message' => $result->get_error_message(), 'errors' => $data['errors'] ?? array(), ), (int) ( $data['status'] ?? 400 ) ); } /* * The draft has served its purpose. Keeping it would leave a copy of the * answers sitting in a transient behind a link that still works, next to * the entry that was just stored properly. */ $this->progress->forget( Request::text( 'formpilot_token' ) ); $form = $this->processor->form( $form_id ); /** * Filters the payload returned after a successful submission. * * @since 1.0.0 * * @param array $payload Response payload. * @param int $submission_id Stored submission ID. * @param Form|null $form Form that was submitted. */ $payload = (array) apply_filters( 'formpilot_submission_response', array( 'message' => $this->messages->success( $form ), 'submission_id' => $result, 'redirect' => '', ), $result, $form ); wp_send_json_success( $payload ); } /** * Returns the unslashed values submitted for the fields. * * Sanitisation happens per field in the validator, which knows the type each * value belongs to. * * @return array Raw values keyed by field key. */ private function submitted_values(): array { $raw = Request::raw( FieldView::NAME_PREFIX, 'post' ); return is_array( $raw ) ? $raw : array(); } }