Question

I have some require fields in some form,I want them be required in somewhere and in another place not be required (I want exactly them , maybe you suggest me use existance field in cck but this fields not in cck.) I used profile2 module with some profile type, I want in profile type edit page as example name field be required and in user registration name field not be required. I try to alter #require property of name field in form alter, it's changed correctly but in validation tell me the name field is required.

in

      function mymodule_form_alter(&$form,&$form_state) {
            if ($form_id == 'user_register_form') {
              $form['profile_detailp']['field_name']['und']['#required']=0;
              ...
              }

      }

any idea ?

Était-ce utile?

La solution

Your method is ok, and have to works but maybe in another module it require again.

     function mymodule_form_alter(&$form,&$form_state) {
        if ($form_id == 'user_register_form') {
          $form['profile_detailp']['field_name']['und']['#required']=0;
          ...
          }

  }

Autres conseils

Text field need do it like this

function mymodule_form_alter(&$form,&$form_state) {
  if ($form_id == 'user_register_form') {
    $form['profile_detailp']['field_name']['und'][0]['value']['#required']=0;
  }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top