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…
Related Posts:
- Applying OO patterns and principles to plugin development
- Is there documentation reference for forms in menu and setting pages?
- How to create a custom post-new.php page for plugin , no wp menu
- How to Maintain url on form submit
- Objective Best Practices for Plugin Development? [closed]
- How do i best handle custom plugin page actions?
- How to create an API for my plugin?
- Is it ever okay to include inline CSS in plugins?
- Plugins in symlinked directories?
- In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
- PHP error with shortcode handler from a class
- Best way to abort plugin in case of insufficient PHP version?
- $_POST form request with admin-post
- How can I configure Docker for developing and deploying a custom theme?
- What do you think about custom designed plugin/theme options UIs?
- No Error Log File, no debug info
- Using a plugin class inside a template
- Where to put third party PHP library?
- Handling results from data hooked into admin_post
- Is the new WordPress 3.1 admin bar pluggable and how can I extend it?
- How to create a flexible abstraction for WP_Query?
- What is the real intention for admin-post.php?
- How to use PanelColorSettings in custom Gutenberg block?
- Getting a peer review for my new plugin?
- What is the correct way to build a widget using OOP
- Optimize shortcode callbacks
- How to integrate a PHP webmail script into the backend of WordPress?
- How to make method from plugin available in theme?
- Using filters and actions for plugin API?
- Is There A Hook To Process The Content Of The Text Widget?
- What is the recommended way to create plugin administration forms?
- Using OOP plugin’s methods throughout the website
- Single Responsibility Principle and WP Classes
- How to Change the Entire WordPress Admin panel Look and Feel?
- How to log plugin errors to plugin error_log file
- How Can I Add a Filter to Class Instance Only?
- Which to use to execute code during the saving of a plugin settings page?
- Allowing for multiple template views on the Gallery Settings page when using the Visual Editor
- The ideal place for storing persistent PHP objects
- Using Primary Color in Plugin Block
- Using AJAX in a plugin to submit form – REALLY confused
- Plugin Architecture/Design Pattern – is better to use a private Observer/Mediator Pattern for plugin subclasses or WP add_action?
- When is it appropriate to put functions on page template vs. functions.php?
- Custom theme sufficient or custom plugin neccessary for this feature set?
- When to check if a function exists
- How to create custom home page via plugin?
- Post from front-end with post types, categories and taxonomies
- Front-End Form Submission in Shortcode
- Check spam in custom form – akismet
- Adding callback function for wp_ajax_ has no effect
- Sessions not creating correctly in custom function
- Use a PHP file as action for a form in a WordPress plugin, what’s the correct way?
- Featured Image not showing in admin
- How to use wp_set_password in a plugin?
- Using a front controller in a WordPress plugin, any suggestions?
- How Can I setup WP CLI on Windows development machine running AMPPS?
- WP_LOCALIZE_SCRIPT doesn’t work
- Front-End Interfaces Without Shortcodes
- Nuance in adding CPT and TAX to a submenu
- set_sale_price in WooCommerce [closed]
- Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?
- Delete a specific item menu when I deactivate my plugin
- Best Practices for Creating and Handling Forms with Plugins?
- Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?
- Plugin options page – form with two different submit buttons
- WordPress Ajax callback function from plugin – OOP
- How do you render_callback for register_block_type to a method in another class?
- Get the password key when using the wp_new_user_notification_email filter
- Order properties should not be accessed directly
- How to sanitize user input?
- How to deal with equal & similar arguments for a function?
- Executing a function upon webhook calling wordpress
- How to Create database table when Plugin installed/activated, and delete database when Plugin deleted
- Customizer: widget-synced triggers twice
- WordPress not working on localhost
- Adding functions to hooks from within a class
- how to use hook deleted_user into custom function to delete user from custom table
- Disable The Events Calendar plugin from loading its scripts
- Registering and using actions which return results in a Plugin class
- Advice on plugin structure
- Where to store the name of a custom table?
- WordPress is automatically linking plain text email addresses
- Is Using WordPress Supplied WYSIWYG Advisable?
- ServerSideRender and Media Object: attributes passing image data object to php renderer even though it’s not set
- Creating a shortcode, but getting tied up with OOP and Classes?
- WooCommerce registration password field not displaying
- wordpress plugin php file processing form
- Is it possible to change a term slug before being saved to the database?
- How to add custom fields to the all users page
- Maximum lifetime for nonce
- Clearing caches on plugin uninstall
- How to use a hook to override an update_post_meta call in a plugin?
- Add code inside specific wordpress standard function
- Custom Taxonomy to dropdown box on adminside wordpress
- Create a free scripts and styles template within a plugin
- Error on inserting a form value to database
- Multiple options pages validation for a plugin
- How to modify the comments to be displayed in a post?
- How can I turn a custom wordpress page into a product page?
- How can we display product price $104 on the cart while the credit card payment method is checked?