Case: I have a form in the page which enables users to add certain values in a simple text file. Now I want to redirect to the same page after values have been added successfully.
The read/write code all works great, I even put redirection code but this would display warning that header information is already sent.
Headers I tried:
header("Location: some_url_here_in_same_site");
wp_redirect("some_url_here_in_same_site");
My Form code:
if(isset($_POST['txtName'])}
// form validation code here
if(successful)
wp_redirect("some_url_here_in_same_site");
}
PROBLEM:
- how can we do redirection in wordpress after form submission in our plugin?
ob_startwonb’t work, so don’t suggest me this either
Ok I managed to do it using Hooks. I did redirection using the code below. Note that the form action is set to
admin-post.phpThen in my plugin’s main file, I added the following:
Where, the function definition is as follows:
Also note that the first argument is derived from
admin_postwhich is a reserved word is combined with theactionhidden field in the form above.after the evaluation that form has been submitted in above
add_action, functionRAGLD_process_hw_formwill be called which is meant to validate form entries and take actions/redirections accordingly.This is the solution I could think of for the time being, you can suggest your answers if you feel they are more effective.