0

The plugin I am working on contains shortcodes with forms on them. Upon form submission (POST), I do some database work, and then planned on redirecting to another page after the db work is complete. When I attempt this, I get the "Headers Already Sent" warning. Within the shortcode function, how do I call my redirect sooner than get_headers? Do I need to use some separate callback function?

1 Answer 1

2

You have to hook an earlier action to check if the form was submitted. Something like:

function wpa_process_form(){
  if( isset( $_POST['my_form_data'] ) ){
      // process form and redirect
  }
}
add_action( 'init', 'wpa_process_form' );
2
  • And this is another function that is tied to init, correct? Not my same shortcode function?
    – clockwiseq
    Commented May 27, 2013 at 19:11
  • correct, separate from your shortcode function.
    – Milo
    Commented May 27, 2013 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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