Receiving the "Please enter in a valid email address" error on a custom module's Fuel input form.

edited December 2012 in Bug Reports
Hello,

I'm receiving the above error (in the Fuel backend) when entering in any valid email value for a custom module email field. Here is the code I'm using to require the "contact_email" field in my custom module:

public $required = array('name', 'password', 'subscription_type_id', 'contact_name', 'contact_email');

It appears as though the valid_email will automatically run whenever the field name contains the word "email" in the name somewhere. I wasn't aware initially this was supposed to happen, and I can't find more information about this behavior in the User Guide. This has been working just fine before, so why all of a sudden is this now not working?

I also did a quick Fuel forum search, but turned up nothing relevant. I did come across this post that seemed to be a problem with the valid_email function:
http://getfuelcms.com/forums/discussion/371

Here's what my valid_email function looks like in my validator_helper, which differs from the above forum post (mine has the value {2,6} instead of {2,4}. Any reason why they are different?

function valid_email($email) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email)) ? FALSE : TRUE; }

Comments

  • edited 11:46PM
    By default, models come with the following property that will auto validate fields. The key is a regular expression to match the field name and the value is the function it maps to:
    public $auto_validate_fields = array( 'email|email_address' => 'valid_email', 'phone|phone_number' => 'valid_phone' );
    Change this value on your model and it should work.
  • edited 11:46PM
    Wow, that worked! Thanks a bunch for the help!
Sign In or Register to comment.