The plugin Formidable Forms has been brought up a few times on our forums, though for something as simple as a contact form we at GD would recommend a simple lightweight contact form such as the one we created here rather than adding a new plugin but we have been asked a few times how to add Formidable Forms to GD tabs so we will show you how to do that below.
Install Formidable Forms plugin
I thought we would start off with a simple one as many of you might not even know about Formidable Forms, its a free plugin which has a paid pro version for extra features though for our examples you will only need the free version.
You can find the plugin here: https://wordpress.org/plugins/formidable/ or you can simply search for “Formidable Forms” in your add new plugin screen in WP admin.
Create a Form
We are not going to go through the process of creating the form but rather the purpose of the form. For our example we will create a simple booking form, this form should appear on our Hotels Custom Post Type (CPT) and only show if the owner has filled out the email field so in essence two criteria must be filled before we even show the form tab on the details page:
- Must be in the Hotel CPT
- Must have the email field filled in
Conditionally add the tab to the details page
This is where we have to add a few little code snippets to your child theme functions.php, i will try and explain everything with code comments which start with a //
Add the tab:
Add the tab content and call the Formidable shortcode
This is great but filling out the form and sending it will only send it to the email address in the settings, usually the admin email, we want to send it to the listing email.
Make the form send to the listing email address
So we have our form emailing to the admin email address and now we need it to also send to the listing email address, to do this we will have to add a hidden field to the form that is specific per listing, we will add the post ID as a hidden field:
Now we know when the form is submitted we can get the post ID which will allow us to get any info about the place. So now lets tell the form to to email the listing email when submitted.
Add listing name to email subject
Great so far the form will send to the site admin and the place owner, but as the site admin we might not know what listing it is referring to so we will add the listing name to the email subject.
You can see the demo here: http://wpgeo.directory/hotels/5-stars/four-seasons-hotel-chicago/#booking_form Now we have a booking form that shows only on hotels CPT and if the place has the email field filled, when submitting the form it will be sent to the site admin and the listing email field and the subject will contain the listing name so the admin can keep track of who the booking is for.
And the email title will read: Booking form for: Four Seasons Hotel Chicago
Let’s say for the 95% of Hotels the booking form will do but maybe we have a few special hotels than need their own booking form, an individual booking form that will superseded the original booking form. First we would create a new individual form and because this form is specific to one hotel we can adjust the email to send direct to them and forget about having to add it with hooks. Then to be able to add a form individually we can just use a post meta field or we could use a GD admin only field to store the shortcode but for this example we will just use a post meta field, here our new form has the ID 4. Add the shortcode to the individual hotel:
Then we would slightly edit the earlier code to show the individual form if available
The GeoDirectory Team!