I have a contact form previously used in static websites that I’d like to adapt to use in WordPress. I realize there are numerous plug-ins such as Contact Form 7, but would rather use this since it’s simple and I’m familiar with it. Basically, on submission the form page goes to a second PHP page for the post action, rendering a confirmation note with all of the entered data while simultaneously sending an HTML email using the same data.
The flat HTML structure is:
examplesite.com/contact/page-contact.php = Form Page
examplesite.com/contact/confirmation/page-form-mail.php = Output Page
This has worked fine for my non-CMS purposes. To adapt to WordPress, I set both up as Pages, and included all the form PHP in their respective page templates. Hence:
wpsite.com/contact – “Contact” page template = “page-contact.php”
wpsite.com/contact/confirmation – “Confirmation” page template = “page-form-mail.php”
My problem is in referencing the confirmation page file in the contact form’s action so the confirmation page actually works within WordPress.
When the confirmation page URL is loaded independently, the output skeleton (without the data) is displayed correctly within WordPress. But hard-coding the actual directory path or using other WP method to generate same (i.e.,
action=“http://wpsite.com/contact/confirmation/” ) produces blank output – I assume because PHP is referencing the directory and not the template file, even though the confirmation page is set up using the template.
Alternatively, the confirmation output page can instead be referenced directly via:
action="<?php bloginfo('stylesheet_directory'); ?>/page-form-mail.php"
This is functional (it outputs and emails the data) but is no longer within WordPress and of course exposes the full template URL path:
Seems I’m missing something pretty basic here. How do I reference the actual confirmation php file in the form action and still keep it within WP?
Thanks for any suggestions!
Note: initially I was using “name” as one of the form variables until I realized that was one of WP’s internals, so then I custom-prefixed all my variables but it’s still not working. (In reading other form questions here, that seems to be a common problem!)