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?

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' );
  • And this is another function that is tied to init, correct? Not my same shortcode function? – clockwiseq May 27 '13 at 19:11
  • correct, separate from your shortcode function. – Milo May 27 '13 at 19:15

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.