I submit the form to admin-post.php:
<form action="<?php echo admin_url('admin-post.php') ?>" method="post">
<input type="hidden" name="action" value="some-action">
<input type="text" name="somename">
</form>
And handle it in the backend:
add_action( 'admin_post_some-action', function () {
$isValid = // SOME VALIDATION HERE
if($isValid){
wp_redirect('next-step'); //redirect to the next form
return;
}
wp_redirect('current-step'); //redirect back
});
If the form is not valid, I want to redirect back to the form with filled data and highlighted invalid inputs. The problem is that wp_redirect does not return any data at all. So user will need to fill all the data mannually again without even understanding wjat was wrong. I found 2 solutions:
- Use get param in the wp_redirect - it may be good for just one input, but it will be awful, especially for the file and passwords inputs.
- Use $_SESSION - it's a bit better, but still rough way to implement this.
- Use curl - it's very dirty solution for the WP
I guess there should be some simple default way to handle this, as it's quite major thing. Any ideas?