Reputation: 1499
I create a hook_form_alter and i want to change the input value depending on a select option.
I catch the name value :
global $user;
$user_fields = user_load($user->uid);
$name = $user_fields->field_user_name['und']['0']['value'];
Actually i use form states :
$form['field_name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $name,
'#weight' => 4,
'#states' => array(
'visible' => array(
'select[name="who_is_registering"]' => array('value' => REGISTRATION_REGISTRANT_TYPE_ANON),
'#default_value' => '',
),
'required' => array(
'select[name="who_is_registering"]' => array('value' => REGISTRATION_REGISTRANT_TYPE_ANON),
),
),
);
the goal is to set the name if the select value is different from anon (REGISTRATION_REGISTRANT_TYPE_ANON) and hide the input ... and to show an empty field on the other case.
Upvotes: 0
Views: 445