0

I ma trying to add foundation classes to my #user-register-form fields in D7

<div class="form-item form-type-textfield form-item-name">
  <label for="edit-name">Username <span class="form-required" title="This field is required.">*</span></label>
 <input class="username form-text required" type="text" id="edit-name" name="name" value="" size="60" maxlength="60">
<div class="description">Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.</div>
</div>

I have tried using template overrides like I have with my other custom fields

field--field_homepage_body.tpl.php

But with no luck any help would be appreciated.

  • hook form alter gives the whole form - I would like the individual fields – LeBlaireau Jul 4 '14 at 14:57
1

You can do this by altering the form in your custom module hook_form_alter(){} or in template.php of your active theme.

Just add the classes in the attributes array().

Or you can create a user-login.tpl.php file following this link, Its already answered here with this code.

<?php
    function operationscheck_theme_theme() {
    $items = array();
    $items['user_login'] = array(
   'render element' => 'form',
   'path' => drupal_get_path('theme', 'operationscheck_theme') . '/templates',
   'template' => 'user-login',

    'preprocess functions' => array(
   'operationscheck_theme_preprocess_user_login'
   ),
);
    $items['user_pass'] = array(
   'render element' => 'form',
   'path' => drupal_get_path('theme', 'operationscheck_theme') . '/templates',
   'template' => 'user-pass',
   'preprocess functions' => array(
   'operationscheck_theme_preprocess_user_pass'
  ),
);
 $items['user_register_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'operationscheck_theme') . '/templates',
'template' => 'user-register-form',
'preprocess functions' => array(
'operationscheck_theme_preprocess_user_register_form'
 ),
);

return $items;
}
?>

<?php
   function operationscheck_theme_preprocess_user_login(&$vars) {
      $vars['intro_text'] = t('This is my awesome login form');
    }
   function operationscheck_theme_preprocess_user_login(&$vars) {
     $vars['intro_text'] = t('This is my awesome pass form');
   }

function operationscheck_theme_preprocess_user_register_form(&$vars) {
    $vars['intro_text'] = t('This is my super awesome reg form');
   }

 function operationscheck_theme_theme(&$existing, $type, $theme, $path) {
  $hooks = operationscheck_theme_theme($existing, $type, $theme, $path)

  $hooks['user_login_block'] = array(
 'template' => 'user-login',
 'arguments' => array('form' => NULL)
 );

// @TODO: Needs detailed comments. Patches welcome!
return $hooks;

}

function operationscheck_theme_preprocess_user_login_block(&$variables) {
  $variables['intro_text'] = t('This is my awesome login formX');
  $variables['rendered'] = drupal_render($variables['form']);
}
 ?>

Please check if it is the code snippet you were looking for.

| improve this answer | |
0

Will be best if you use hook_form_alter() function. In the hook you can set needed template for the render, form add needed class or any wrapper element

| improve this answer | |

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.