Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Update: This question now has a clone: http://stackoverflow.com/questions/13184335/drupal-how-to-make-a-form-that-captures-a-value-from-request

I have been trying to make a form that captures a value passed in from $_REQUEST.

  1. A field is displayed only if a $_REQUEST variable exists (done)
  2. The user can modify the field
  3. The field is validated in whatever way
  4. The (modified) value gets used

In this specific case, I am using a hook_user function, but I hope that the solution is applicable to any Drupal form.

Here's a simplified version of my code where the user would have an extra field to specify that they have a favorite fruit if they were to register using the following URL:


function fruity_user($op, &$edit, &$user, $category = NULL){
    switch($op) {
        // Add extra fields if $_REQUEST contains values for them
        case 'register':
            if($_REQUEST['fruit'] == 'pineapple'){
                $fields['user_reg_info']['profile_fruit'] = array(
                     '#type' => 'textfield'
                    ,'#description' => 'Your favorite fruit (if applicable)'
                    ,'#locked' => 0
                    ,'#value' => $_REQUEST['fruit']
            return $fields;

        // check registration for mistakes
        case 'validate':
            if ($edit['form_id'] == 'user_register') {
                if ($edit['profile_fruit']){

        // runs after the new user is inserted
        case 'insert':
                db_query('INSERT INTO user_fruits SET `uid`=%d `fruit`="%s"',array($user->uid, $edit['profile_fruit']));

            // record information
            watchdog('user', t('user %user picked out a fruit',array('%user' => $user->name)));

With the above code, the field does make itself visible only when $_REQUEST['fruit'] is present but if you change your fruit to "watermelon" on the form, insert still uses "pineapple".

share|improve this question
up vote 0 down vote accepted

The answer was to use #default_value instead of #value.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.