So, I’ve spent far too long messing with formmail.php.. but I just can’t resist getting everything just right! I was getting an obscure error, which requires a little form field validation.
The problem
I found during testing that if I populated form fields with the excellent Web Developer toolbar for Firefox, I would get the following error:
The following error occurred in FormMail :
mail_failed
**********
Error=Failed to send email
The error whilst using the formmail tag <fmerroritemlist /> the only feedback displayed to the user was:
There was an error in processing your form…
Not so helpful.
Whilst using the error handling tags <fmerrorcode /> and <fmfullerror />, the feedback was little better:
Error Code: mail_failed
Failed to send email
The failure was due to the email address being faulty. The Web Developer Toolbar populated the field with ‘email’ (the name of the field), and formmail.php choked on the invalid address.
The solution
The solution was found in the following forum post at Tectite.com. We simply add a condition:
If an email is submitted, test it, and notify the user if it’s bad!
Just add the following condition to your form:
<input type="hidden" name="conditions" value=":# #IF#email#email ~ /^[a-z0-9_.]+@[a-z0-9_]+\.([a-z0-9_.]+)*[a-z0-9_.]$/i ## Please enter a valid email address.#">
Sorted! Now the user will be told “Please enter a valid email address” if, and only if, they enter something in the email field.
Please note that in the formmail documentation the author recommends that you use either conditions, or required fields. I’ve found no problems whilst using them together in my simple scenario, but if you encounter gremlins in your error handling, RTFM.
2 Comments
Or: for a text to mean something is for it to have somehow established a norm for such responses. ,
i just had to approve this comment ‘cos its so wacky…
I read the Behemoth Series by Peter Watts recently, and he looks at the culture of evolving bots on the net.. this one is interesting because it had no payload! No link to a dodgy pharma sales site or anything.. Ironically, it has survived the spam queue because of this.. is this the first recognition of digital Cuteness Factor?!