I’m writing my first WordPress plugin and need to add a page that does processing of a form. I have a shortcode that adds a form to any page. That form needs to post to a URL where I can process the data (save to DB and send email).
I initially added a process.php file in my plugin directory and posted to that, which works to get the posted data, but I have no access to any wordpress features (which I need to access the database table I created).
Ideally I would like to have a url like /plugin-name/process that I can use. I’m assuming there has to be a way to have that direct to a function in my main plugin code file, but I can’t seem to find how to do that.
I’m a complete noob with WordPress (primarily a .NET developer, but with PHP experience), so any help would be appreciated.
Few things are not clear, but as per my understanding I can suggest below solution :
use wordpress ‘init’ action to catch posted data, for example
In above code ur_form_process_fun() function trigger at initializing stage of wordpress, and your form’s action should be default site url
action="<?php site_url()?>"
, so that, submitted data will be posted to base url of site and it can be available toinit
action.unique_hidden_field
can be unique hidden input field of your form, this is just to confirm that data is coming from your form.Hope this may solve your problem. 🙂
You could use the add_feed function to create the action path page, write something similar to that in your plugin functions.php or anywhere you define you wordpress actions:
In your-action-file.php you should be able to use wordpress functions as usual.
Refs:
https://codex.wordpress.org/Rewrite_API/add_feed
https://www.pmg.com/blog/a-mostly-complete-guide-to-the-wordpress-rewrite-api/