I am unable to remove the label from a form element of the registration form.

I have:

  • Enabled the kint module for debugging
  • Implemented hook_form_alter() and tried to change the form variables

    function drupalfresh_form_user_register_form_alter(&$form, FormStateInterface $form_state, $form_id) {
      $form['field_company_name']['#attributes']['widget'][0]['#title'] = t('');

This doesn't change the form.

This is how the form element appears.


  • I cant do it in the css but i dont want to go by the css way. Sep 5, 2018 at 7:27

2 Answers 2


You try the code below:


Actually the can be changed using this code:

$form['field_company_name']['widget'][0]['value']['#title'] = $this->t('WHATEVER');

  • In Drupal 8 this doesnt seem to work. Sep 5, 2018 at 7:41
  • Sorry the answer was edited Sep 5, 2018 at 7:44
  • $this in here gives a fatal error though its close to what i was looking . Solved. Thanks Sep 5, 2018 at 7:50

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.