Drupal中自定义登录页面
通过覆写template定义新的user_login表单来为自定义登录页面。
方法:
1. 本站使用的主题是Rorty。来到\sites\all\themes\rorty,打开template.php,添加代码。目的是为登录页面指定一个新的模版,路径是templates/user/user_login,渲染类 型是form表单
function rorty_theme(&$existing, $type, $theme, $path) { $hooks['user_login'] = array( 'template' => 'templates/user/user_login', 'render element' => 'form', ); // $hooks['user_register_form'] = array( // 'template' => 'templates/user/user_register', // 'render element' => 'form', // ); return $hooks; }
2. 根据'template'参数路径,在templates目录下建立user\user_login.tpl.php文件。
3. 仿照之前的登录页面。重写代码。比如再写form标签了。
<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 type="text" id="edit-name" name="name" value="" size="60" maxlength="60" class="form-text required"> <div class="description">Enter your Rorty username.</div> </div> <div class="form-item form-type-password form-item-pass"> <label for="edit-pass">Password <span class="form-required" title="This field is required.">*</span></label> <input type="password" id="edit-pass" name="pass" size="60" maxlength="128" class="form-text required"> <div class="description">Enter the password that accompanies your username.</div> </div> <?php print drupal_render($form['form_id']); ?> <?php print drupal_render($form['locale']); ?> <?php print drupal_render($form['honeypot_time']); ?> <div class="form-actions form-wrapper" id="edit-actions"> <input type="submit" id="edit-submit" name="op" value="Log in" class="form-submit" /> <input type="button" name="op2" value="Register" class="form-submit" onclick="location.href='user/register'"/> </div>
4. 清空缓存。重新来到登录页面www.xxx.com/user/login,查看效果。