How do I evaluate the user's email address in a drupal site?
I am using the notifications module in a small drupal 6 site and want to be able to send the user either sms or email messages based on the value of the user's email address field.
I have access to a gateway, so all I have to do is add an "@" and the gateway's address to the end of the cellphone number.
So, I want to tell patrons to enter either their cellphone number or address, but have a script that evaluates what is in that field. Basically, if there is already a "@" (meaning they entered their email address), the value is not altered. But if there isn't a "@" and the value is 10 digits (a phone number), then automatically the "@gatewayaddress" is added.
I can figure out the PHP with preg_match to do this, but how do I get the value of the field when the account is created?
I find info on customizing the user registration, but I'm thinking I should write a simple module to do this to make sure this is easier to maintain down the road.
I am not using drupal's sms framework and gateway modules because text messages are not being sent, and trying out development versions of the modules still don't work, and broke my site. Also, this gateway that I am using is available to my employer for free, and most importantly, it just friggin' works.
Can someone help me get my head around this to get started?
@nmc thanks. I'm new to module development, but I really need this functionality.
Here is the function for my module, which isn't working. How do I get on the right track? function emailsmsfield_user($op,&$edit,&$account,$category = NULL) {
//if creating an account or updating
if($op == 'insert' || $op == 'after_update') {
/*checking for '@' symbol. If it is missing, the value gets the gateway address
added to the end*/
开发者_如何转开发 if(preg_match('[^@]',$user->mail[0]['value'])) {
$user->mail[0]['value'] = $user->mail[0]['value'] . 'gateway.address.com';
}
}
}
This is the regular expresion for validating an email
preg_match("/^[^@]*@[^@]*\.[^@]*$/", $email_address)
You may be able to use the hook_user
function to check and alter the user's email field so that you can update it accordingly.
Remember to use form_set_value
if you are changing the form fields so that they are persisted.
You may even be interested in using the built in valid_email_address
function in Drupal which will check to see if something is an email address.
And yes, you will have to put all of this customization in your own little module.
精彩评论