2017-06-27 58 views
0

我已經從我的核心php網站通過curl提交表單值到drupal站點(http://xxyz.com/drupal_hook_register.php)鏈接。在這個頁面中,我試圖將電子郵件,密碼直接插入到Drupal數據庫中。請幫我解決這個問題如何在drupal的獨立php頁面添加鉤子?

  // define static var 
     define('DRUPAL_ROOT', getcwd()); 
     // include bootstrap 
     include_once('./includes/bootstrap.inc'); 
     // initialize stuff 
     drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 

     $email = $_REQUEST['email']; 
     $password = $_REQUEST['password']; 
+0

你想在內容保存期間準確地工作嗎?你在做什麼?保存用戶或內容頁面? – Anurag

+0

我在drupal目錄中寫了一個單獨的php頁面,並試圖將該字段保存到用戶表中的新記錄(drupal數據庫) – mike

回答

1

在這裏你走!

if($_POST) { 
    //Bootstraping Drupal 
    require_once './includes/bootstrap.inc'; 
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 

    $account = new stdClass(); 
    $account->name = $_REQUEST['username']; 
    $account->mail = $_REQUEST['mail']; 
    $account->init = $_REQUEST['mail']; 
    $account->pass = user_password($_REQUEST['pass']); // you could use a random characters here too 
    $account->status = 1; 
    user_save(Null, $account); 
    if ($account->uid) { 
     drupal_set_message('Created new user with id %uid', array('%uid' => $account->uid)); 
     echo 'success'; 
    } 
} 

試試這個,因爲這可以幫助你!

+0

感謝您的回答。我已經嘗試過這個鏈接http://codekarate.com/blog/create-user-account-drupal-7-programmatically – mike