我使用template.php和user-profile-form.php自定义了编辑个人资料视图 全部显示正确,但提交(和删除)按钮.. 我正在使用自适应主题,我修改过这样:
的template.php
function adaptivetheme_theme(&$existing, $type, $theme, $path) {
return array(
'user_profile_form' => array(
'template' => 'templates/user-profile-form',
'render element' => 'form',
),
);
}
function adaptivetheme_preprocess_user_profile_form(&$vars) {
$vars['form']['account']['name']['#description'] = t('blabla');
$vars['form']['submit']['#value'] = t('Save profile');
$vars['form']['delete']['#value'] = t('Delete account');
$vars['account'] = drupal_render($vars['form']['account']);
$vars['theme_select'] = drupal_render($vars['form']['theme_select']);
$vars['picture'] = drupal_render($vars['form']['picture']);
$vars['signature_settings'] = drupal_render($vars['form']['signature_settings']);
$vars['contact'] = drupal_render($vars['form']['contact']);
$vars['timezone'] = drupal_render($vars['form']['timezone']);
$vars['submit'] = drupal_render($vars['form']['submit']);
$vars['delete'] = drupal_render($vars['form']['delete']);
}
然后在user-profile-form.tpl.php:
<div id="user-profile-form">
<?php echo $account; ?>
<?php echo $timezone; ?>
<?php echo $submit; ?>
<?php echo $delete; ?>
</div>
帐户的编辑表单正确显示。我已经尝试成功添加/删除变量(即$ timezone)但缺少提交/删除。 我不知道有什么不对.. 我试图更改变量'submit'和'delete'的名称,但仍然没有按钮显示。当然,我每次都需要(而不是)清除缓存。 我没有JS隐藏按钮.. 我通过Panel中的自定义块渲染此表单:
<?
module_load_include('inc', 'user', 'user.pages');
global $user;
print drupal_render(drupal_get_form('user_profile_form', $user));
?>
Panels可能有问题???
任何想法都表示赞赏:)
阅读本文
二万
答案 0 :(得分:3)
我忘了“[行动]”......:
$vars['submit'] = drupal_render($vars['form']['actions']['submit']);
$vars['cancel'] = drupal_render($vars['form']['actions']['cancel']);
并且“删除”按钮最初没有显示,因为它被称为“取消”,并且其#access参数被发送到FALSE。 Thx DPM;)
现在,问题在于,当我触发提交按钮时,表单未发送,只是重新加载页面。如果我设法解决这个问题,我会更新。
答案 1 :(得分:3)
页面只是重新加载,因为您忘记渲染隐藏的表单元素。要在模板预处理中执行此操作,您可以使用类似的内容:
function THEME_preprocess_user_profile_form(&$variables) {
$hidden = array();
foreach(element_children($variables['form']) as $key)
{
$type = $variables['form'][$key]['#type'];
if($type == "hidden" || $type == "token"){
$hidden[] = $variables['form'][$key];
}
}
$variables['hidden'] = $hidden;
//Dont forget to report your variables like you already did ...
}
然后当它完成时,在模板文件中渲染$ hidden变量
<?php print render($hidden);?>
你去了!