0

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->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

1

Try the following code to set a field to required.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.