Quick Form Handler
Sometimes a person needs a quick form handler for testing a form, especially if you are a web developer or software creator. This article has one. Free.
Quick Form Handler is meant for temporary use.
It was created when something was needed to process contact form submissions during a support cycle of the form's regular form handler.
Quick Form Handler accepts a form submission with the method="post" attribute in the form tag. It sends you an email with all form field names and their values — except file uploads (which are discarded). Also, if there are duplicate field names, only one will survive and be published in the email.
Whether or not it is intentionally included in the form submission, Quick Form Handler ensures these items are in the email it sends out:
-
The user's IP address.
-
The browser's user-agent string.
-
The location of the Quick Form Handler script.
Upon form submission, the browser is redirected to the location specified in form field name="redirect" or, if no such field, to the domain's home page.
This software works with pretty much any form so long as there is no file upload and no duplicate field names.
Quick Form Handler is suitable only for temporary use because it has no anti-spam features and no error checking. Eventually, spambots will find it. And people do inadvertently type wrongly-formatted information into text fields.
Still, Quick Form Handler is handy if you need a form handler to quickly throw onto your site for testing — or when you need software to temporarily service a form while you develop, update, or troubleshoot the form's regular software.
For permanent or longer-term use, you would, of course, use a professional form handler, one that has error checking and can detect spamming attempts. Consider Master Form .PHP (PHP software on your server) or Spam‑free Form (a free service).
Here is the Quick Form Handler source code. Below the source code is information about the one place that must be customized and another that is optional.
<?php /* Quick Form Handler Version 1.1 March 29, 2019 Version 1.0, March 27, 2019 Version 1.1, March 29, 2019, to send all field value types except type="file". Will Bontrager Software LLC https://www.willmaster.com/ Note: If the form contains a field name="redirect", then the value is where the software will attempt to redirect the browser to. */ // Customization: Specify the To and Subject lines for the email. // ($EmailTo is required. $EmailSubject may be left as is.) $EmailTo = "will@example.com"; $EmailSubject = "Form Submission"; // End of customization. if( ! count($_POST) ) { echo 'Inappropriate access.'; exit; } if( empty($_POST['IP']) ) { $_POST['IP'] = $_SERVER['REMOTE_ADDR']; } if( empty($_POST['UA']) ) { $_POST['UA'] = $_SERVER['HTTP_USER_AGENT']; } if( empty($_POST['ME']) ) { $_POST['ME'] = $_SERVER['PHP_SELF']; } $EmailResponse = array(); $EmailResponse[] = "Date/time stamp:\r\n" . date('r'); foreach( $_POST as $k => $v ) { $EmailResponse[] = "$k:\r\n$v"; } mail($EmailTo,$EmailSubject,implode("\r\n\r\n",$EmailResponse),"From: {$EmailTo}"); $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : '/'; header("Location: $redirect"); exit; ?>
Customization:
There are two places to customize. Updating the first is required. The second may be left as is.
-
Replace
will@example.com
at$EmailTo = "will@example.com";
with the mail address where the form information email shall be sent to. -
Form Submission
at$EmailSubject = "Form Submission";
may be replaced with the email subject of your choice.
Upload the PHP script source code to your server, giving it a file name that ends with .php
Replace your form's action
attribute value with the newly-uploaded PHP script's URL.
You now have a quick form handler for temporary use.
(This article first appeared with an issue of the Possibilities newsletter.)
Will Bontrager