Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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' );
share|improve this answer
    
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
    
THANKS A MILLION!!! Worked like a charm! –  ClockwiseQ May 27 '13 at 19:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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