User profile form make custom form required I'm trying to use a hook to make a user field (company name) required based on assigned roles so:

if($form['#id'] == 'user-profile-form') {
  dsm($form);
  if (!in_array('BPSA user', array_values($user-&gt;roles))) {
    $form['field_dealership']['#type'] = 'hidden';
    $form['field_company_name']['und']['#required'] = 1;
    $form['field_company_name']['und'][0]['#required'] = TRUE;
  } else {
    $form['field_company_name']['#type'] = 'hidden';
  }
}


It's not working and I can't find any other 'required' form elements?

Ps I know this would only rewrite if the user was not a BPSA user.

Thanks,

Steve
Try the following code to set a field to required.

$form['field_company_name']['und']['0']['value']['#required'] = TRUE;