Use valid_email_address() to validate email. was: Unable to do email verification

bartman76 - January 16, 2009 - 12:17
Project:Author Contact
Version:6.x-1.1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hi I install and everything is working fine, however when I input an invalid email it failed to validate, is there any way to trigger this?

Thanks

#1

JustJamesAus - January 30, 2009 - 00:51
Status:active» postponed (maintainer needs more info)

What email are you trying to validate (or invalidate)?

Keep in mind that it only validates to make sure the email is a possible email address by seeing if it looks like an emailey kind of string - it can't check if it's an actual factual real live email address.

If you let me know the addresses/strings you want to fail I'll test it and see what we can do.

#2

ressa - May 31, 2009 - 19:01

Thanks for a great module.

I have the same problem: I can enter anything, "rhjdkrghkd gdr" for example, in the email field, and it is accepted. It seems like the validation isn't being run at all...

Thanks

#3

adrinux - June 3, 2009 - 14:07
Title:Unable to do email verification» Use valid_email_address() to validate email. was: Unable to do email verification
Status:postponed (maintainer needs more info)» active

This may be related to authorcontact not using the drupal core validation function and doing verification itself :)
I think it should be using valid_email_address() to validate addresses, not that regex, so current code:

function authorcontact_form_validate($form_id, $form_values) {
    //check the email address is valid
    if(isset($form_values['email'])) {
        if (!preg_match('/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,7})+$/', $form_values['email'])) {
            form_set_error('email', t('Invalid email address'));
        }
    }
}

should be*:
function authorcontact_form_validate($form_id, $form_values) {
    //check the email address is valid
    if(isset($form_values['email'])) {
        if (!valid_email_address($form_values['email'])) {
           form_set_error('mail', t('The e-mail address you specified is not valid.'));
        }
    }
}

* partially cribbed from comment module, you may want to make more changes :)

Function documentation:
http://api.drupal.org/api/function/valid_email_address/6

- changed issue title to reflect this

#4

adrinux - June 3, 2009 - 16:47

Actually there's more to this issue than that, it doesn't actually validate the email address at all (as everyone says). You can enter anything. Will look into this further tomorrow if no one else does before then :)

#5

JustJamesAus - June 3, 2009 - 22:53

Thanks Adrinux, that's a hot tip - I was simply doing it myself because I wasn't aware of valid_email_address().

I'll work that in asap. (While fixing CVS...)

#6

adrinux - June 4, 2009 - 10:40
Status:active» needs review
AttachmentSize
authorcontact_fix_email_validation-01.patch 1.03 KB

#7

ressa - June 8, 2009 - 12:51

Thank you for the patch, nice job!

The validation now works, but I had to add a comma to line 56:
'#required' => true,

I have added the comma to the patch and reuploaded it, I hope correctly?

I haven't applied a patch before, but it's not that difficult. If anybody else want to test the patch, just follow the directions here http://drupal.org/patch/apply.

AttachmentSize
authorcontact_fix_email_validation-02.patch 1.03 KB

#8

adrinux - June 9, 2009 - 20:20

Good catch, but no, you can't simply edit the patch, as it stands patch would entirely ignore your change. you need to diff compared to the original again.

Corrected patch attached.

AttachmentSize
authorcontact_fix_email_validation-03.patch 1.09 KB

#9

JustJamesAus - July 13, 2009 - 03:55
Status:needs review» fixed

Thanks Adrinux for the patch and ressa for the testing. I've updated the 6.x dev version with this validation method.

Thanks again!

#10

System Message - July 27, 2009 - 04:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.