After processing form data in one of plugin file I need to redirect to some other page. When I used wordpress function or php wp_redirect()/header() it shows me error like "header already send" html already start printing before this file. So How can I redirect after processing form data in plugin file.

  • 2
    hook your form processing to an action that runs before the page is printed.
    – Milo
    Nov 26 '14 at 14:32
  • Thanks @Milo. My problem solved by adding a hook. Added my answer what I implemented. Nov 27 '14 at 6:54

Added hook to process all form values and than redirecting as per process result:

Added below PHP code in theme/functions.php:

function process_form(){
 //code goes here
add_action( 'admin_post_appointment_form_process', 'process_form' );

And added/updated below html to form:

<form name="frm1" id="frm1" action="<?php echo home_url()?>/wp-admin/admin-post.php" method="post">
<input type="hidden" name="action" value="appointment_form_process">

Thanks for @Milo comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.