1

我已经使用 template.php 和 user-profile-form.php 自定义了编辑配置文件视图所有显示正确,但提交(和删除)按钮..我正在使用自适应主题,我已经修改如下:

模板.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),但缺少提交/删除。我不知道出了什么问题。我尝试更改变量“提交”和“删除”的名称,但仍然没有出现按钮。当然,我每次需要(而不是)时都清除了缓存。我也没有隐藏按钮的 JS。我通过 Panel 中的自定义块呈现此表单:

<?
module_load_include('inc', 'user', 'user.pages');
global $user;
print drupal_render(drupal_get_form('user_profile_form', $user));
?>

也许面板有问题???

任何想法表示赞赏:)

感谢阅读

二湾

4

2 回答 2

3

我忘记了“[动作]”..:

  $vars['submit'] = drupal_render($vars['form']['actions']['submit']);
  $vars['cancel'] = drupal_render($vars['form']['actions']['cancel']);

并且“删除”按钮一开始并没有出现,因为它被称为“取消”,并且它的#access 参数被发送到 FALSE。谢谢 DPM ;)

现在,问题是当我触发提交按钮时,表单没有发送,它只是重新加载他的页面。如果我也能解决这个问题,我会更新。

于 2012-11-27T22:27:49.400 回答
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);?>

你去吧!

于 2013-01-31T21:31:25.917 回答