我正在使用drupal表单来构建联系我们表单。
我想将我的联系人数据发送给salesforce。
我与我们联系表单已采取行动" https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8"。
我希望在将表单详细信息发送到salesforce之前对其进行验证,因此我使用了hook_validate函数来验证表单。
如果我直接在hook_menu中提及#action,那么它会直接将数据发布到salesforce,但在发送之前不会对其进行验证。
所以,我正在尝试使用cURL向salesforce发送数据。
这是我的表格:
function contact_us_form($form_state){
$form['orgid'] = array(
'#name' => 'orgid',
'#type' => 'hidden',
'#value' => 'xxxxxx'
);
$form['retURL'] = array(
'#name' => 'retURL',
'#type' => 'hidden',
'#value' => 'http://www.example.com'
);
$form['external'] = array(
'#name' => 'external',
'#type' => 'hidden',
'#value' => '1'
);
$form['name'] = array(
'#type' => 'textfield',
'#size' => 40,
'#id' => 'name',
'#title' => t('First and Last Name'),
'#prefix' => '<table><tr><td>',
'#suffix' => '</td></tr>',
'#required' => TRUE
);
$form['email'] = array(
'#type' => 'textfield',
'#size' => 40,
'#id' => 'email',
'#title' => t('Valid Email Address'),
'#prefix' => '<tr><td>',
'#suffix' => '</td></tr>',
);
$form['phone'] = array(
'#type' => 'textfield',
'#id' => 'phone',
'#title' => t('Phone Number'),
'#size' => 40,
'#prefix' => '<tr><td>',
'#suffix' => '</td></tr>'
);
$form['subject'] = array(
'#type' => 'textfield',
'#size' => 40,
'#title' => t('Subject'),
'#prefix' => '<tr><td>',
'#suffix' => '</td></tr>'
);
$form['desc'] = array(
'#type' => 'textarea',
'#size' => 40,
'#title' => t('Description1'),
'#prefix' => '<tr><td>',
'#suffix' => '</td></tr>'
);
$form['type'] = array(
'#name' => 'type',
'#type' => 'hidden',
'#value' => 'Web-to-case'
);
// // Adds a simple submit button that refreshes the form and clears its contents -- this is the default behavior for forms.
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#prefix' => '<br><tr><td style="padding-left:150px;">',
'#suffix' => '</td></tr></table>'
);
return $form;
}
表格正确处理。以下是我的验证功能:
function contact_us_form_validate($form, $form_state) {
//logic to check fields.
}
以下是我的提交代码无效: 理想情况下,cURL调用不应该返回,因为我在表单中提到了retURL,并且retrurn URL将由salesforce设置。目前我没有被重定向到retURL.NO任何条目都将转到salesforce。
function contact_us_form_submit($form, $form_state){
$temp = $form_state['values'];
$ch = curl_init();
foreach ($temp as $key => $value) {
//Set array element for each POST variable (ie. first_name=Arsham)
$kv[] = stripslashes($key)."=".stripslashes($value);
}
$query_string = join("&", $kv);
//The original form action URL from Step 2 :)
$url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
//Open cURL connection
$ch = curl_init();
//Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($kv));
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
//close cURL connection
curl_close($ch);
}
答案 0 :(得分:0)
我想你想......
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //returns response as data.
我知道这听起来很愚蠢,但你已经检查过你是否安装了cURL并且在php中启用了它?
此外,您应该尝试将$ result检查为false。
if($result=== false)
{
echo "Error Number:".curl_errno($ch)."<br>";
echo "Error String:".curl_error($ch);
}
只是为了看看是否有问题,就像你因为一些安全问题而无法发布salesforce,比如你没有传递salesforce.com的用户名和密码或你帐户的API密钥。