2012-12-19 23 views
2

我對Drupal幾乎是全新的,我正在開發一個項目,我們的目標之一是發送不同的註冊電子郵件給一組用戶註冊後。我的想法是創建一個可以在電子郵件中使用的令牌,由用戶的角色決定。我進入user.module並添加到這裏。 角色;Drupal 6.x根據角色向用戶發送不同的歡迎電子郵件

if($welcomer == 'Student Member'){ 
$copying = "SPECIAL EMAIL TEXT"; 
} 
else{ 
$copying = "GENERAL EMAIL TEXT"; 
} ?> 

然後在令牌部分我設置了

<?php '!sendit' => $copying, ?> 

如果使用到目前爲止,這什麼也不做,甚至else語句不觸發。所以我的問題是,我將如何去做這件事?這是最佳的方式,還是有更簡單的方法去實現它?

+2

你不應該砍了Drupal核心,看看這個信息關於如何自定義Drupal:http://stackoverflow.com/a/13644975/1068167 – span

回答

0

Don't hack the Drupal core或者當您更新Drupal時,您的所有代碼都將丟失。

我沒有的環境下所以這段代碼沒有進行測試的時刻來測試,但你想是這樣的:

function yourModuleName_form_user_register_alter(&$form, &$form_state) { 
    // Add your own function to the array of submit callbacks 
    $form['#submit'][] = 'yourModuleName_user_register_submit'; 
} 

function yourModuleName_user_register_submit($form, &$form_state) { 
    // I don't think this line is correct but don't have an environment to test in at the moment 
    // Do a print_r here on $form_state['values'] and see where the user roles are stored 
    $roles = $form_state['values']['roles']; 

    if(in_array('Student Member', $roles) { 
     // send student email here 
    } elseif(in_array('Teacher Member', $roles) { 
     // send teacher email here 
    } 
} 
+0

好吧,謝謝你的提示。我將如何去使用你編寫的代碼?正如我所說,我對drupal沒有經驗。 – user1917147

+0

您將需要創建自己的自定義模塊並將代碼放在那裏。有一個教程在這裏做這個:http://drupal.org/node/361112編輯:剛剛意識到你的Drupal 6,這裏是正確的教程:http://drupal.org/node/206753 –

相關問題