Plugin Form Submission Best Practice

Send the form action either to your homepage, or to a specific page URL. You can’t have $_POST handling within the template because you need to redirect after your process it, and redirect needs to be fired before any HTML output.

// you should choose the appropriate tag here
// template_redirect is fired just before any html output
// see - http://codex.wordpress.org/Plugin_API/Action_Reference
add_action('template_redirect', 'check_for_event_submissions');

function check_for_event_submissions(){
  if(isset($_POST['event'])) // && (get_query_var('pagename') === 'events) 
    {
       // process your data here, you'll use wp_insert_post() I assume

       wp_redirect($_POST['redirect_url']); // add a hidden input with get_permalink()
       die();
    } 

}

You could also check for a nonce to make sure the data was submitted from the right place…

Leave a Comment