0
我正在使用Drupal創建一些自定義的表單提交給第三方,我試圖捆綁我的表單結果 - 其中一些應用了一些轉換函數給他們 - 發送給表單收件人。如何用值的變量創建一個PHP鍵控數組
我在簡單的表單上使用了Drupal的drupal_http_request函數,它的'運行良好,但現在我的一些結果賦予了變量值,我不知道如何創建一個繼續傳遞值的鍵控數組變種
我知道,當我將表單直接發送給我的第三方時,他們會收到正確的結果,但是我試圖將結果發送給他們,但是重定向到我自己網站中的頁面,所以我知道我的表單在至少 - 這只是使用嘗試編碼的功能,所以我有控制重定向不。 但我甚至不知道是否有鎖陣列可以有變量,因爲它的值或者沒有,或者如果它的語法
的事這是我的代碼:
function formshare_nameform_submit($form_id, &$form_state) {
// Lookup share matrix return value
$shareMatrixValue = setShareMatrixValue($form_state['values']['image_id']);
$langResultsCode = setLangForShare($langCode);
$gender = setGenderForShare($form_state['values']['gender']);
$first_name = $form_state['values']['first_name'];
$last_name = $form_state['values']['last_name'];
$email = $form_state['values']['email'];
$email_friend1 = $form_state['values']['email_friend1'];
$email_friend2 = $form_state['values']['email_friend2'];
$email_friend3 = $form_state['values']['email_friend3'];
$message = $form_state['values']['massage'];
$optin = $form_state['values']['optin'];
$category = $form_state['values']['category'];
$image_id = $shareMatrixValue;
$id_langue = $form_state['values']['id_langue'];
// Make an array of values to pass to 3rd party.
$pass_these = array();
$pass_these['shareMatrixValue'] = $shareMatrixValue;
$pass_these['langResultsCode'] = $langResultsCode;
$pass_these['gender'] = $gender;
$pass_these['first_name'] = $first_name;
$pass_these['last_name'] = $last_name;
$pass_these['email'] = $email;
$pass_these['email_friend1'] = $email_friend1;
$pass_these['email_friend2'] = $email_friend2;
$pass_these['email_friend3'] = $email_friend3;
$pass_these['message'] = $message;
$pass_these['optin'] = $optin;
$pass_these['category'] = $category;
$pass_these['image_id'] = $image_id;
$pass_these['id_langue'] = $id_langue;
// Post the data to 3rd party.
$url = 'http://mythirdpartysite.com';
$headers = array('Content-Type' => 'application/x-www-form-urlencoded');
$data = drupal_query_string_encode($pass_these);
drupal_http_request($url, $headers, 'POST', $data);
}
我已經嘗試使用參考VAR是這樣的:$ pass_these ['gender'] =&$ gender;但它不起作用。我知道我應該收到一封電子郵件回覆。我對PHP不太好,你能給我一個關於如何設置一個stdClass對象的例子嗎? – StephanieF
'$ object = new stdClass(); $ object-> gender =&$ gender;'但是你可以使用'$ pass_these ['gender'] = $ gender;'然後在另一邊獲得值,不知道爲什麼你需要引用變量。 – SparK