Drupal Answers Asked by SenthilKumar on November 30, 2021
How do I remove form element attributes from a form using hook_form_alter()
?
For example, given the following HTML markup, how do I remove form-text?
<input type="text" class="form-text required" maxlength="255" size="60" value="" name="title" id="edit-title">
Insert the following into your custom module:
function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id){
switch($form_id){
case 'YOUR_FORM_ID':
$form['title']['#required'] => FALSE;
break;
}
return $form;
}
That makes the title field optional. You can check the different form element types and the properties that go with them here: https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
And you can read more about hook_form_alter here: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_alter/7
Answered by Ollie on November 30, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP