2012-11-26 72 views
1

我已經使用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']); 

} 

然後在用戶配置文件的form.tpl.php:

<div id="user-profile-form"> 

<?php echo $account; ?> 
<?php echo $timezone; ?> 
<?php echo $submit; ?> 
<?php echo $delete; ?> 


</div> 

的ACC的編輯形式ount顯示正確。我嘗試成功地添加/刪除變量(即$時區),但提交/刪除失蹤。 我不知道什麼是錯的.. 我試圖改變變量'提交'和'刪除'的名稱,但仍然沒有任何按鈕顯示。當然,我已經清除了每次需要的緩存(而不是)。 我沒有JS隱藏按鈕既不.. 我一個面板中顯示這個表單通過自定義塊:

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

也許有問題,面板???

任何想法表示讚賞:)

THX閱讀

二萬

回答

3

我忘了 「[動作]」 ..:

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

而 '刪除' 按鈕沒起初不會出現,因爲它被稱爲「取消」,其#access參數被髮送到FALSE。 Thx DPM;)

現在,問題是,當我觸發提交按鈕,表單不發送,它只是重新加載他的頁面。如果我也能解決這個問題,我會更新。

2

該頁面只是重新加載,因爲您忘記了呈現隱藏的表單元素。要在模板預處理做,你可以使用類似的東西:

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 ... 
    } 

然後,當S DONE渲染$隱變量在模板文件

<?php print render($hidden);?> 

而且你去那裏!