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.

Some easy points on offer...

I wish to action a PHP script from a WordPress page but where is the best place to store the script? The script works perfectly fine using a non-WordPress environment in a flat HTML directory structure.

and I want to action it from the page using the following code:

<form class="contact_form" form action="phpmailersub.php" method="post" enctype="multipart/form-data" name="contact_form" onsubmit="return validateForm()">

What will then go into form action="file" ?

At current the submit action is searching for a page http://current/route/to/contact-test/phpmailersub.php but obviously, WordPress cannot find it.

Your help would be very much appreciated! If I can do anything to articulate my query or if you need any additional material I will try my best to help.

UPDATE

At current the PHP file (phpmailersub.php) and class.phpmailer.php sits in: http://damtech.it/demo/etap/wp-content/plugins/phpmailersub.php

and my current code looks like this:

<form class="contact_form" action="&lt;?php bloginfo('http://damtech.it/demo/etap/wp-content/plugins/'); ?&gt;&lt;p&gt;/phpmailersub.php" enctype="multipart/form-data" method="post" name="contact_form" onsubmit="return validateForm()">
<table class="contact">
<tbody>
<tr>
<td class="third"><input type="text" name="cf_mercury" required="" /></td>
<td><span style="color: #3c4247;">   Name</span><span style="color: #3492d1;">*</span></td>
</tr>
<tr>
<td class="third"><input type="email" name="cf_jupiter" required="" />
<span class="form_hint">Correct format "name@url.com"</span></td>
<td>   <span style="color: #3c4247;">E-mail</span><span style="color: #3492d1;">*</span></td>
</tr>
<tr>
<td colspan="2"><textarea name="cf_uranus" required="" rows="6"></textarea></td>
</tr>
</tbody>
</table>
<table class="contact">
<tbody>
<tr>
<td width="50%"><button class="submit" onclick="document.getElementById('contact_form').submit()" type="submit">Send message</button></td>
<td style="text-align: right;" width="50%"><span class="c-clear"><button class="reset" style="color: #3c4247; letter-spacing: -0.5px;" onclick="document.getElementById('contact_form').reset()" type="reset">reset</button></span></td>
</tr>
</tbody>
</table>
</form>
share|improve this question

3 Answers 3

up vote 1 down vote accepted

You are actually closer in your first attempt.

My recommendation would be to create a folder called "scripts" in the WP root and put your PHP script files in here as well as your attachment(s). You will then need to declare the full path in your action attribute as the script does not now share the same file path as in your "flat HTML file structure".

Your action code will then be action="http://damtech.it/demo/etap/scripts/phpmailersub.php"

Easy as that. No need to create a plugin at all (although this may be better practice). Don't forget to change the details within phpmailersub.php to accommodate the changes made in terms of attachment paths (server path), page directs etc.

share|improve this answer
    
Exactly what I needed! Thank you –  Paul May 22 '13 at 10:47
1  
im glad it helped –  BarmyArmy May 22 '13 at 10:51
2  
I would suggest to use swiftmailer though, it's better for sending mail, and it is reliable to the bone. –  Panagiotis May 22 '13 at 11:21

Do not call your PHP files directly. This will break, because in some setups, the plugin directory might be located on another domain, and your file would operate without the WordPress context now.

Use the current URL as form action URL (or admin-post.php), then test if the request is a POST request and handle the form submission. Then redirect back to the original page with a 303 status header.

share|improve this answer
    
These files will be stored somewhere within the WordPress setup. I am not sure I understand but I will give it a whirl. It was so simple in plain HTML. –  Paul May 21 '13 at 8:57
    
+1 for the only answer that was right on this topic –  kaiser Jun 6 '13 at 0:23

Assuming there is no contact form plugin which matches your needs, the proper way to do it in wordpress is to write and add an appropriate page template to your theme which contains and handles your form. Once done you associate the page in which the form should be displayed with the page template and then your action path is simply "".

share|improve this answer
    
There is a plugin, but it costs and wished to tackle the issue myself in the spirit of learning. –  Paul May 21 '13 at 13:17

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.