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
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? Commented May 27, 2013 at 19:11
-