Software for Simple and Complex Forms
The PHP Form Processor software is bare bones, tightly coded, and easy to implement.
Use it when you need to put up a form quickly — survey, signup, … . Actually, use it for pretty much any form, simple or complex, and whether or not you're in a hurry.
It can be implemented on WordPress and non-WordPress sites.
In essence, you specify the email address to send form results to and then upload the PHP Form Processor file to your server.
Now you're ready to submit forms to it. As many forms as you want. Change the forms whenever you want. It's all the same to the software. It will dutifully email the form results to the address you specified.
PHP Form Processor can't handle file uploads, though. Nor can it handle multi-page forms. For those features, or to save form results on the server, or for custom-formatted emails, use Master Form .PHP or Master Form V4.
For general forms and for email-only notifications, PHP Form Processor can do the job.
Installing PHP Form Processor
For both WordPress and non-WordPress sites, the PHP Form Processor software needs to be installed.
But it's easy. Specify a custom email address and upload the file to your server.
Here's the source code. Detailed instructions follow.
<?php /* PHP Form Processor Version 1.0 March 3, 2017 Will Bontrager Software LLC https://www.willmaster.com/ Copyright 2017 Will Bontrager Software LLC This software is provided "AS IS," without any warranty of any kind, without even any implied warranty such as merchantability or fitness for a particular purpose. Will Bontrager Software LLC grants you a royalty free license to use or modify this software provided this notice appears on all copies. */ /* Customization section. */ // Specify the email address where form results are to be sent: $ResultsTo = "name@example.com"; //Optionally, specify a subject line for the results email. $EmailSubject = "PHP Form Processor form results"; /* End of customization section. */ if( ! count($_POST) ) { echo 'Inappropriate access.'; exit; } $content = ''; foreach($_POST as $k=>$v) { $k = trim(stripslashes($k)); $content .= "$k\n\t".(is_array($v)?print_r($v,true):trim(stripslashes($v)))."\n\n"; } foreach( preg_split('/[,\s]+/',trim($ResultsTo)) as $email ) { if( strpos($email,'@')===false ) { continue; } mail($email,$EmailSubject,$content,"From: $email"); } if( empty($_POST['thanksURL']) ) { echo 'Thank You!'; } else { if( headers_sent() ) { echo "<script>location.href='{$_POST['thanksURL']}'</script"; } else { header("Location: {$_POST['thanksURL']}"); } } exit; ?>
Specifying the email address —
Replace the blue colored email address (name@example.com
) in the source code with your own email address.
To send the form results to more than one email address, add as many as you need. Multiple email addresses need be separated with a comma and/or a space. Example:
$ResultsTo = "name@example.com, another@example.com, person@example.com";
The email subject line —
Optionally, the subject line of the email the PHP Form Processor sends may be changed. It's colored green in the above source code.
Uploading the PHP Form Processor source code —
When the PHP Form Processor source code file has been customized with an email address, name it PHPformProcessor.php
— or other name that works for you so long as .php is at the end of the file name. (The instructions on this page assume PHPformProcessor.php
is the file name you go with.)
With the file saved and named, it's ready to upload to your server.
Upload the file into any directory where PHP scripts can run. That would be any directory where browsers can load web pages.
When uploaded, make a note of its URL. (The instructions on this page assume http://example.com/PHPformProcessor.php
)
PHP Form Processor has been installed.
The Form
Create a form or make a copy of a form you are already using somewhere.
The URL of the PHP Form Processor is the URL you specify for the action
attribute of the form tag. Example:
<form id="my-form" method="post" action="http://example.com/PHPformProcessor.php">
There is a requirement for the form and a suggestion.
A form requirement — The form needs to have a hidden field containing name="thanksURL"
and the field's value being the URL of the thank-you page. Example:
<input type="hidden" name="thanksURL" value="http://example.com/thankyou.html">A form suggestion — Give the form fields meaningful names. The reason is that the email PHP Form Processor sends is composed of the form field names and the values the form user provided. With meaningful names, it will be easier to differentiate the fields.
With your form created, you're almost ready to implement the functionality.
Before you do, consider adding spam resistance.
Spam-Resisting the Form
To add spam resistance to your form, do these two things:
-
(a) Verify your form tag has an id value. And (b) specify the action value as index.php (or another file name that is not a form handler). Example:
<form id="my-form" method="post" action="index.php">
In the above example,
my-form
is the form field's id value andindex.php
is the action value. -
Below the form, below the cancel
</form>
tag, add this JavaScript (with correct form id value and URL to PHP Form Processor).<script> document.getElementById("my-form").action = "http://example.com/PHPformProcessor.php"; </script>
Verify that
my-form
specified in the JavaScript is identical to your form's id value.Change
http://example.com/PHPformProcessor.php
to the URL of the PHP Form Processor installed on your server.
Now, when a robot loads the form it sees the form's action value as index.php
(or other file name you specified). The index.php
URL is where the robot is most likely to try to submit the form to.
For real browsers, the JavaScript below the cancel </form>
tag changes the form's action value to the URL of the PHP Form Processor software so the form submits correctly.
Implementation
For non-WordPress sites, put the form on your web page and you're good to go.
For WordPress sites:
-
Save the form to a file named form.html or any other file name you prefer.
-
Upload the file to your server. Make a note of its URL (for the next step).
-
Use the Insert Here plugin to insert the form into your web page.
Now, you are good to go, too.
For all sites:
Whether non-WordPress or WordPress, do test your form before providing its URL to the public.
Test that (i) the form submits to your installation of the PHP Form Processor and (ii) an email with the form contents is sent to the address provided in the PHP Form Processor source code file.
By the way, once the PHP Form Processor software is installed on one of your domains, you can put the forms on any of your domains.
(This article first appeared in Possibilities ezine.)
Will Bontrager