Over the past few months I’ve been kicking around a cakePHP project in my spare time. I understand most of cakePHP’s core concepts, and tonight I was developing a user registration form that validates the user’s email via ajax before submitting the form.
After organizing my code, I ran a quick test with “asdf@asdfasdf.com” and was pleasantly rewarded with a successful validation message. Then I decided to get tricky and see what cakePHP was made of. I erased the email and tried again with “blahblah@poiuytrewq.co.uk” which promptly failed to validate. Eghad!
Turning to google I started searching for “cakePHP bad email validation.” Surely someone more clever than I had noticed that cakePHP’s email validation was not up to snuff, and hopefully I could find a better solution. Google assaulted me with silence. All I could find were links back to cakePHP’s Core Validation Rules Documentation.
After about twenty minutes of searching elsewhere, I began to think the error must be in my own code, so I returned to the cakePHP Cookbook, only to discover this little tidbit of information:
Passing a boolean true as the second parameter for [the email validation] rule will also attempt to verify that the host for the address is valid.
<mindblown>
CakePHP’s core validation not only checks whether or not an email address is well formed, it also determines whether the host for the address exists! Changing the email in my application to “blahblah@amazon.co.uk” prompted me with a fresh success message.
</mindblown>
Time to clean my brains off of the wall.
No related posts.
Tags: cakePHP, forms, frameworks, php
