[support] Persistent random form value

Larry Garfield larry at garfieldtech.com
Mon Apr 21 16:38:21 UTC 2008


Hello, support at .

I have a form in a Drupal 6 site where I want to have a random value in it.  That random value should be really-random between different users.  However, it should be the same value for displaying the form, processing the form, and submitting the form.  However, the form's constructor function gets called multiple times throughout the lifetime of a form.  Currently I am doing the following:

$new_password = user_password();
$form['admin_account']['account']['pass'] = array(
  '#type' => 'value',
  '#value' => $new_password,
);
$form['admin_account']['info'] = array(
  '#type' => 'item',
  '#title' => $t('Your new administrator password is'),
  '#value' => $new_password,
  '#description' => $t('Remember to write this down!'),
);

(Yes, this is in an install profile's form alter.)  That's great, but when the constructor and alters are called on submit, it will get a new password from user_password() that is not the same as the one the user was just given a moment ago.  It should still validate, I think, but what's saved won't be what the user was just given as a password.

Does anyone know how to make the above work as intended?  

--Larry Garfield



More information about the support mailing list