Submit form in WordPress
Submit the form in WordPress
WordPress has a generic handler to deal with all forms –
admin-post.php
.
If you include a hidden field in your form called
action
, you can then hook into a function of your choice with all the goodness of WordPress included.echo "<form action='".get_admin_url()."admin-post.php' method='post'>";
echo "<input type='hidden' name='action' value='submit-form' />";
echo "<input type='hidden' name='hide' value='$ques' />";
{ Enter the rest of your first block of code from above here }
And then in your
functions.php
file (or any other php
the file that you have included via functions.php
), you can use this method.add_action('admin_post_submit-form', '_handle_form_action'); // If the user is logged in
add_action('admin_post_nopriv_submit-form', '_handle_form_action'); // If the user in not logged in
function _handle_form_action(){
{ Enter your second block of code from above here }
}
Post a Comment