0

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) {
      kint($form);
      $form['field_company_name']['#attributes']['widget'][0]['#title'] = t('');
    }
    

This doesn't change the form.

This is how the form element appears.

screenshot

  • I cant do it in the css but i dont want to go by the css way. – Jignesh Rawal Sep 5 '18 at 7:27
0

You try the code below:

$form['field_company_name']['widget'][0]['value']['#title']='';
1

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. – Jignesh Rawal Sep 5 '18 at 7:41
  • Sorry the answer was edited – Alireza Tabatabaeian Sep 5 '18 at 7:44
  • $this in here gives a fatal error though its close to what i was looking . Solved. Thanks – Jignesh Rawal Sep 5 '18 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.