Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

http://wpsite.com/wp-content/themes/wpsite-theme/page-form-mail.php

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!)

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I would like to recommend you to read The Rewrite API: The Basics article. Especially pay attention to the Add Custom Endpoint section where you can find how to create what you need.

share|improve this answer
    
My problem appears to have been a basic error (WP was reading something in what I thought was commented code). With that removed, URL resolved itself. But your link is great for problems like these, have it bookmarked. Thanks! –  boomturn Mar 2 '13 at 17:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.