Validating form input using Rules

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

Hi!

I'm trying to setup Rules to validate my form input for me, when using CCK fields.

So far I've made 1 form, with one CCK text field, called field_email.

I've tried various ways to get Rules to check if this is a valid email address or not, by using Triggered rules:

ON event My node form is being validated
IF
NOT
condition Execute custom PHP code

DO
action Set form error on element 'field_email[0]'

The custom PHP code is simple:

return valid_email_address($form_state['values']['field_email'][0]['value']);

However .. I cant seem to find any way to actually make this work!
I've tried comparing field elements to text, tried a simple preg_match instead of the valid_email_address function, but they all always evaluate to "true", regardless of my input in the field.

This is the first time since D4 that I'm using Drupal again, so I guess I'm just being rusty ... but, what am I missing?

Thx!

Comments

Are you just trying rules?

JThan's picture

Are you just trying rules? Otherwise you could use the cck Email Module.

Or try:
return valid_email_adress($form['nid']['#post']['field_email'][0]['value']);

any luck validating email

darora's picture

any luck validating email address using Rules module. Thanks

One-zero thing

itangalo's picture

Following some tracks from http://api.drupal.org/api/function/valid_email_address I learned that valid_email_address actually returns one or zero, not TRUE or FALSE. This might the causing your trouble. Try

return (valid_email_address($form_state['values']['field_email'][0]['value'] == 1));

instead, and things might look brighter.
I don't know an awful lot about $form_state, but I presume you have validated that the variable you're looking for is located in the place you're pointing at.

Welcome back to Drupal!
//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: