Override registration module & Hide or show input text drupal 7

76 Views Asked by At

I created a module and a hook to override the registration module form :

function custommodule_form_alter(&$form, $form_state, $form_id)  {
    // retrieve name & surname
    global $user;
    $user_fields = user_load($user->uid);
    $name = $user_fields->field_name['und']['0']['value'];
    $surname = $user_fields->field_surname['und']['0']['value'];
    // var_dump($name); die();

    // check the form_id
    if($form_id=='registration_form'){
        if( $form['who_is_registering']['#options']['registration_registrant_type_me'] =='Myself') {
            $form['field_name']['und'][0]['value']['#default_value'] = $name;
            $form['field_surname']['und'][0]['value']['#default_value'] = $surname;
        } else {
            $form['field_name']['und'][0]['value']['#default_value'] = '';
            $form['field_surname']['und'][0]['value']['#default_value'] = '';
        }
    }
}

In the original module we can hide or display a field depending on the select value. For example if the select is positionned on "Myself", the user mail field is not visible.

I'd like to set the fields to empty if the select is positionned on "Myself" and to show empty fields otherwise.

Actually the name and surname are defined in the fields.

0

There are 0 best solutions below