Email address From User Register Form

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

Hi, I am having a problem to get correct value from "Token replacement patterns", when using Rules with User Register Form. Here is what I try to do: if an internal user (with my company email address) try to register, we don't save the registration info to Drupal, instead of, we redirect him to a page that tells "internal users don't need to register".

I created a rule based on "User register is being validated" event. The "Textual comparison" is checking the email field which is from User Register Form, to see if it's my company's email address. If it is, redirect to "internal users don't need to register" page.

The problem is I am not able to get the email value using Token. The only available Tokens are:
[form_id:string] The string, passed through check_plain
[form_id:string-raw] The string, raw and unfiltered Warning: Token value contains raw user input.
and Tokens for Acting user (which is not useful, since the user is not an acting user yet).

I tried [form_id:string] and [form_id:string-raw], but without luck. Could someone tell how can I get the email from User register form?

Thanks!!

Comments

Hello, does anybody has any

td001's picture

Hello, does anybody has any idea how to get the email from User register form? I tried all the ways I can found:
$form['nid']['#post']['mail']['0']['value']
$form_state['values']['mail']
$form['mail'][0]['#value']
...

But still not able to get it. Please help!

Try dpm() on $form

itangalo's picture

I'm no master on the structure of Drupal forms, but I recommend turning on the Devel module and PHP Filter modules (the latter in core). With these two you can do

<?php
dpm
($form);
?>
and see the entire structure of the form array.

Add a 'Execute custom PHP' action, and you can explore the available data more. (You'll also get a list of the available objects on the action configuration page -- it might even be that you should look in another object.)

In the cases where I have particular difficulties in finding the data I want I run a

<?php
dpm
(get_defined_vars());
?>
, and sometimes you even have to use var_dump() instead of dpm() because of how stuff are printed and rendered.

Good luck!
//Johan Falk, NodeOne, Sweden

Thanks for the info. I have

td001's picture

Thanks for the info. I have added "dpm($form)" to the 'Execute custom PHP' action and was able to see the structure of the form array. However, I am still not able to get the value in the Textual comparison condition. If I add "dpm($form['account']['mail']['#value'])" to the 'Execute custom PHP' action, I was able to get the value.

  • Here are my two texts to compare:
    $form['account']['mail']['#value']
    [user:mail]

  • Here are Forms where events are activated:
    User register
    User profile form

One strange thing is: after the debug is turned on, I was only able to see the variable "acting user" is loaded. But no info for "form", "form_state", or "form_id" are turned on. I am not sure if this is the problem. Did I miss some configurations here?

* 0 ms "User profile form is being validated" has been invoked.
* 0.145 ms Executing the rule "update user name with the email address" on rule set "User profile form is being validated"
* 2.252 ms Loaded variable "acting user"
* 13.54 ms Condition "Textual comparison" evaluated to FALSE.
* 14.198 ms Action execution: "Execute custom PHP code"
* 14.331 ms Evaluation of "User profile form is being validated" has been finished.

Please help! Thanks!

Rules

Group organizers

Group categories

Categories

Group notifications

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