【发布时间】:2026-01-25 08:20:03
【问题描述】:
目前我正在尝试为我的 Drupal 网站的用户个人资料表单设置主题。我在主题的 template.php 文件中使用了 hook_form_alter。
该代码与我用来编辑另一个表单的代码相同,但由于某种原因我无法发现它不起作用。
function THEME_NAME_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_profile_form') {
$form['current_pass']['#prefix'] = '<div class="loginFormBlock">';
$form['current_pass']['#suffix'] = '</div>';
$form['current_pass']['#size'] = '500';
//$form['actions']['submit'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/Login.png');
}
}
现在,注释掉的提交按钮部分在未注释时有效,但 current_pass 位不做任何事情。 Current_pass 是我要主题化的字段的名称。 THEME_NAME 已替换为主题名称。
回答:
按照建议,我查看了 $form 数组。
echo '<pre>';
print_r($form);
echo '</pre>';
看到 current_pass 在 account 数组中,修改代码如下,效果很好。
$form['account']['current_pass']['#size'] = '500';
希望这可以帮助其他人。
【问题讨论】:
-
current_pass 是现有的配置文件字段吗?尝试调试并转储
$form['current_pass'](在更改之前)以查看里面有什么
标签: drupal drupal-7 drupal-theming