How to return variables from admin-post.php

Question

If I submit a form with an action of /wp-admin/admin-post.php, is there a way to return form errors to the originating page?

My form has an input with the action set:

<input name="action" value="enquiry_form" />

I have an actions setup to manage the validation:

add_action('admin_post_enquiry_form', 'mytheme_enquiry_form_submit');

I can return to the original form page with a wp_redirect:

wp_redirect('/contact/');

But how can I pass variables/ messages back to this page after redirecting?

UPDATE:
To add clarification, I was under the impression this was the “correct” way to handle form data, rather than simply adding an init hoot to check for a specific POST variable. There are countless tutorials where people use the admin-post.php action, for example:

WPMUDEV Handling Form Submissions

AdaptiveWeb Handle POST and GET requests in WordPress

SitePoint Handling POST Requests the WordPress Way

0
Alexander Holsgrove 4 years 2017-11-08T13:15:41-05:00 0 Answers 71 views 0

Leave an answer

Browse
Browse