无法呈现提交按钮



我使用模板.php和用户配置文件表单自定义了编辑配置文件视图.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']);
}

然后在用户配置文件表单.tpl 中.php :

<div id="user-profile-form">
<?php echo $account; ?>
<?php echo $timezone; ?>
<?php echo $submit; ?>
<?php echo $delete; ?>

</div>

帐户的编辑表单显示正确。我已经尝试成功添加/删除变量(即$timezone),但缺少提交/删除。我不知道怎么了..我尝试更改变量"提交"和"删除"的名称,但仍然没有显示按钮。当然,我每次都需要(而不是)都清除了缓存。我也没有JS隐藏按钮。我通过面板中的自定义块呈现此表单:

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

也许面板有问题???

任何想法都值得赞赏:)

感谢阅读

尔万

我忘记了"[action]".. :

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

"删除"按钮起初没有出现,因为它被称为"取消",并且其 #access 参数被发送到 FALSE。谢谢 DPM ;)

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

页面只是因为您忘记呈现隐藏的表单元素而重新加载。要在模板预处理中执行此操作,您可以使用类似以下内容:

    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);?>

你去吧!

相关内容

  • 没有找到相关文章

最新更新