Checking for domain in email field - custom PHP rule

Events happening in the community are now at Drupal community events on www.drupal.org.
hixster's picture

HI guys,

I'm new to rules an am stuck on an issue. I am using rules_forms to process some input from a form. I'll describe what I am trying to achieve and hopefully someone can help.

1) My client wishes to prevent any user with a free email account from posting through the contact form.
2) I have set up a rule that triggers on form validation and prints and error for the email field.

I tried to achieve the logic with text-compare, but it's not working for some reason , so I am going down the php route.

Essentially I have a regular expressions:

[a-zA-Z0-9_.]+@(gmail|yahoo|hotmail)(.[a-z]{2,3}){1,2}

That will check if the email contains, yahoo , gmail etc..

when setting up the rule with the text compare I was able to use the token: submitted[email] : to get the value of the email address.

In a nutshell, how do I access the value provided by this token in PHP so I can manually run my regex or any other logic against the email address field.

Any help appreciated, confused and frustrated - I haven't been able to find much documentation pertaining to forms/php with rules.

Many thanks

Hix

Comments

I don't know if you need to

caschbre's picture

I don't know if you need to use the rules module for this. If you go to /admin/user/rules on your site there are user access rules already provided that allow you to deny based on a mask.

Hi Caschbre, Thanks for the

hixster's picture

Hi Caschbre,

Thanks for the reply.

The access rules for users are only for login & account creation, I require this functionality on a site wide contact form.

Has anyone used an PHP with

hixster's picture

Has anyone used an PHP with Rules forms? That may give me a head start

Has anyone used any PHP with

hixster's picture

Has anyone used any PHP with Rules forms? That may give me a head start

This isn't specific to your

thekenshow's picture

This isn't specific to your situation, but it might shed some light on using the Execute Custom PHP Code condition.

--
Less isn't more; just enough is more.
- Milton Glaser

Sorry, that should have

thekenshow's picture

Sorry, that should have included http://groups.drupal.org/node/25672

--
Less isn't more; just enough is more.
- Milton Glaser

Just a validate function?

itangalo's picture

I'm usually not the guy who suggests manual coding over a module, but in this case it seems you're just looking for a complementary validation function for the comment form.

This could be a mini module, instead of a Rules function.

It seems you will have to do some coding – to get the regexp into Rules – so you won't get a no-coding solution anyway. If you make it a mini module you have just some few lines surrounding the expression you want to test, and you don't have to worry about the framework of Rules nor Token. Just hook into the variables.

Hope this might help.
//Johan Falk, NodeOne, Sweden

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week