I am using a 3rd party service that does a scrub of my database for new entries within a specific table. However I am been unable to find a simple form plugin that submits data to the wordpress database inside of a table that won’t affect any of the wordpress functionality. The reason is my hosting provider only allows me one database.
I need to use a form in my wordpress that:
- Captures name, phone, email submitted by end user
- Save to the database
- Redirect user to confirmation page.
Nothing elaborate really and although it would be great to see the results in the wordpress administration it is not necessarily required since I can just use myphpadmin.
In summary:
I need a simple html/php form, where I can just paste the form html onto a page via the wordpress administration via the html/code view for pages. When a user submits the form, it saves it to the wordpress database and then redirects the user to a “thank you” page.
For what I can understand you already have the table in your database.
I don’t know how you have named it, but a best practise (for me a must-do practise) is to name it with the same table prefix of wordpress, that’s the one setted in
wp-config.php
.You also don’t say how this table is structured, but I guess it’s somethimg like:
You can add a shortcode that print the form. In your
functions.php
add:Now just create a post or a page in wp dashboard and simply add
[userform]
: the form is magically printend in the page.As you can see I’ve not added the action attribute to form, in this way the form send post data to same page.
Now you have to save data. add an action on a early hook, look for the
$_POST
, check the nonce and save your data:The code is rough, but should be a valid starting point. Inline comments should help you to understand the workflow.
Be sure to read the documents:
One thing to take into account,
NAME
is a reserved wordpress word, if you use a field called name, when you submit your form, you will obtain a404
not found error.