1

I'm trying to unset the label of a custom form called email. In which the value is in the #title key.

I've tried {{ value|without('title', 'description', 'email.#title') }}

But it is not working

3 Answers 3

0

@Fazeela Abu Zohra try to unset the value in .theme file. write a form alter and kint $form variable .Find your label value

function est_form_alter( &$form, &$form_state, $form_id ) { 
  if($form_id == 'your_form_id'){
    kint($form);
  }

and then simply unset the variable.

unset($form['form_id']['#value']);

Here,i assume you find your variable at $form['form_id']['#value'].Hope it will be useful to you.

0

If it's a custom form you're building from your code then just set the field's title as empty string:

$form['email']['#title'] = '';

If the form is a node form then implement Drupal's hook_form_alter like this:

function MODULE_NAME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'FORM_ID') {
    $form['field_email']['und']['#title'] = '';
  }
}
0

in Drupal 8, you can use hook_form_FORM_ID_alter hook function in your THEME.theme file.

For exemple with theme named custom and FORM_ID named contact_message_custom_contact_form :

/**
 * Implements hook_form_alter().
 */
function custom_form_contact_message_custom_contact_form_alter(&$form, &$form_state, $form_id) {
  unset($form['field_contact_name']['widget'][0]['value']['#title']);
  unset($form['field_contact_message']['widget'][0]['value']['#title']);
  unset($form['field_contact_phone']['widget'][0]['value']['#title']);
  unset($form['field_contact_mail']['widget'][0]['value']['#title']);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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