I have done a lot of researching and haven’t found quite what I am looking for, so I am hoping that I can be pointed in the right direction.
I am developing an Events plugin that will book a ticket from the frontend. This is no different than any other Form submission, but what I am getting confused with is how to handle that from a plugin that is written via OOP with a class.
Most articles that I found say to put the $_POST handling within the template page. Ideally I would like to have this handled by a function within the plugin.
The other thing that I am not sure about is when you submit the form on the frontend, how that actually gets passed to the function on the backend. I am hoping to completely abstract the form processing from any template details.
// events.php
if ( ! class_exists( 'Events' ) ) {
Class Events {
function __construct() {
add_action( 'plugins_loaded', array( &$this, 'includes' ), 1 );
}
function includes() {
require_once( EVENTS_INCLUDES . 'functions.php' );
}
}
}
if ( class_exists( 'Events' ) ) {
$events_load = New Events();
}
// functions.php
function process_form() {
...do form processing here...
...insert booking...
}
I’m not sure what to hook into that would catch that, or where to send the form action too. Thanks for all the help!
-Adam
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 could also check for a nonce to make sure the data was submitted from the right place…