I need to add Placeholder property to Drupal 7 login form from template.php. Not to use a module. and also want to know how to add other attributes like Required etc.
1 Answer
I think it cannot be done unless using the module. You can try like this
1) Adding the hook_form_FORM_ID_alter in the module to add placeholders, required and some other form attributes.
2) In the template file you can call that form using drupal_get_form('form-id', args1, args2, etc..)
3) Finally, pass the form to the tpl file.
Example:
1) In .module
function yourModule_form_user_login_alter(&$form, $form_state) {
$form['name']['#attributes'] = array(
'placeholder' => array (
t('Username')
)
);
$form['name']['#required'] = TRUE;
/* Add other attributes like this*/
}
2) In template.php
$variables['login_form'] = drupal_get_form('user_login');
3) In .tpl.php
<?php print render($login_form); ?>
I hope this will work !!
-
Thanks for your help it's working in template.php. I will also try them in module and .tpl. Commented Sep 29, 2017 at 7:02
-