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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// 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(); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.