Through my work in web development I’ve noticed the high number of times I need to write out a contact or registration form for a client. Each time I get the form fields together and then decide how I want to process the form. This usually entails a client-side validation of certain fields (required fields, email validation, etc) and then a back-end check of those fields before processing them. This process can get pretty repetitive if you do a high volume of projects or sites needing this function. I was looking for a way to process any form I create with the same script each time and thus produced this PHP script. It’s a lightweight, single file form processor (with an additional file for configuration) that has a number of options. The goal of this script is to provide a small footprint resource available to use over and over. For certain forms you may want to implement your own client-side validation of fields before sending them to the form processor. Let’s explore the features:
Features
- A PHP file inspects form data and runs simple validation on empty fields and email addresses
- You have the option of sending the user to a Review page
- Upon review the user can print and/or submit the results once all fields are
- Can submit results to 1 or more email accounts
- Can send a blind carbon copy (bcc) as well
- Email results can be plain text or HTML formatted
- Script can be used in a standalone environment OR as a part of your existing site template
- You can define which fields are required
- You can define which fields (if any) should not be displayed back to the user when they check the results before submission (eg: IP address)
Form Field Compatibility
This script successfully processes the following field types:
- text
- radio
- checkbox
- select & options(single and multiple)
- hidden
- textarea
- image
Requirements
- This script requires PHP 4.0.7 or newer
Be sure to read the docs to understand how to successfully setup multiple checkboxes within a single “name” and multiple select options within a single “name”.
Comments
Abraham
When updating my site I didn’t account for my download and source code links. You can now find the zip and GitHub repository on the sidebar of the project page. Let me know if you have any questions!
Hi Erik!
I believe I’ve found a bug. Line 85 of settings.php reads:
$from_nameField
and it should read:
$from_name_field
‘cos that’s what’s in the processor.
GBY
Stuart
Thanks Stuart. You are indeed correct. The file has been updated accordingly. Thanks for letting me know!
My pleasure. I’ve been using this since you first published it, and am very grateful for it. It fits into our Drupal site like a dream.
I have another one. My plain-text notification includes the lines:
Senditalready
Goforit
What’s that all about?
Here’s a suggestion for you. I’ve elected to have the timestamp in the e-mail. Now the time given is the time on the server, which is CST. However, the form users are in the UK which is 6 hours ahead of CST, so when they submit the form the timestamp says 10:00 but the form was submitted at 16:00.. Would it be possible to add an offset value to the settings file, something like timezone_correction=6?
GBY
Stuart
Thanks again Stuart. I fixed the ‘Senditalready’ bug. That was basically a trigger to send the email rather than display the results preview page. I didn’t change the version number so just re-download 2.0.2 if you already downloaded it after the other bug fix.
As for the time, I’ll take a look and make a change sometime soon. Thank you for pointing it out!
I believe I’ve found another bug!
Line 61 of the processor reads:
if ( $fromEmailIsInForm )
but it should read:
if ( $from_email_in_form )
to make it agree with settings.php and follow the general structure of the other variables.
I forgot to mention that I’ve also added a “Go Back” button to the review page. Even if there are no errors, a user may want to change what’s being submitted after review. Accordingly, I’ve changed line 215 of the processor to:
$block .= “\t<input type=\“button\” name=\“back\” value=\“Go Back\” id=\“back\”><input type=\“button\” name=\“print\” value=\“Print Results\” id=\“print\” onclick=\“window.print();\” ><input type=\“submit\” name=\“submit\” value=\“Send Results\” id=\“submit\” /></p>\n </form>\n</div>\n”;
Your Words of Wisdom
I want to test your Catch-All PHP Form Processor script please.
Abraham Mbongoo Evina on Nov 10th at 11:53 am