我有一個我在我的網站上的salesforce網絡到首席表單。一切正常,但沒有recaptcha或任何方式來防止垃圾郵件。因此,我下載了recaptcha,完成了一切設置,並且我也按照指示here採取$ _POST數據,驗證recaptcha是否正確,然後將其提交給salesforce。帶Salesforce的Recaptcha網頁到首頁
我得到了所有的設置,但是當我提交表單時,它只是進入我的check-this-first.php(我把它稱爲contactFormConfirm.php)頁面,只是空白。它沒有觸及retURL或實際提交給salesforce。
任何能夠幫助我的燈光都會讓人驚歎。先謝謝你。
這裏是我使用的代碼:
Salesforce的網站,以導語:
<form action="/contactFormConfirm.php" method="POST">
<input type=hidden name="oid" value="#############">
<input type=hidden name="retURL" value="http://www.google.com">
<div class="row span12 pull-left">
<div class="span6 pull-left">
<label for="first_name" class="span3">First Name</label>
<input id="first_name" maxlength="40" name="first_name" size="20" type="text" class="span9" />
</div>
<div class="span6 pull-left">
<label for="last_name" class="span3">Last Name</label>
<input id="last_name" maxlength="80" name="last_name" size="20" type="text" class="span9" /><br>
</div>
</div>
<div class="clearfix"></div>
<div class="row span12 pull-left">
<div class="span6 pull-left">
<label for="title" class="span3">Title</label>
<input id="title" maxlength="40" name="title" size="20" type="text" class="span9" /><br>
</div>
<div class="span6 pull-left">
<label for="email" class="span3">Email</label>
<input id="email" maxlength="80" name="email" size="20" type="text" class="span9" /><br>
</div>
</div>
<div class="clearfix"></div>
<div class="row span12 pull-left">
<div class="span6 pull-left">
<label for="phone" class="span3">Phone</label>
<input id="phone" maxlength="40" name="phone" size="20" type="text" class="span9" /><br>
</div>
<div class="span6 pull-left">
<label for="00N4000000231ne" class="span3" style="position:relative; top:-1.2em;">Profile:</label>
<select id="profile" name="00N4000000231ne" title="Profile" class="span9"> <option value="">--None--</option>
**[other options hidden for privacy]**
</select>
</div>
</div>
<div class="clearfix"></div>
<div class="row span12 pull-left">
<div class="span6 pull-left">
<label for="company" class="span3">Company</label>
<input id="company" maxlength="40" name="company" size="20" type="text" class="span9" /><br>
</div>
<div class="span6 pull-left">
<label for="country" class="span3">Country</label>
<input id="country" maxlength="40" name="country" size="20" type="text" class="span9" /><br>
</div>
</div>
<div class="row span12 pull-left">
<div class="span6 pull-left">
<label for="street" class="span3">Address</label>
<textarea name="street" class="span9"></textarea><br>
</div>
<div class="span6 pull-left">
<label for="city" class="span3">City</label>
<input id="city" maxlength="40" name="city" size="20" type="text" class="span9" /><br>
</div>
</div>
<div class="clearfix"></div>
<div class="row span12 pull-left">
<div class="span6 pull-left">
<label for="state" class="span3" style="position:relative; top:-1.2em;">State/Province</label>
<input id="state" maxlength="20" name="state" size="20" type="text" class="span9" /><br>
</div>
<div class="span6 pull-left">
<label for="zip" class="span3">Zip</label>
<input id="zip" maxlength="20" name="zip" size="20" type="text" class="span9" /><br>
</div>
</div>
<div class="clearfix"></div>
<div class="row span12 pull-left">
<div class="span6 pull-left">
<label for="00N40000001V9wA" class="span3" style="position:relative; top:-1.2em;">Product Interest:</label>
<select id="productInterest" multiple="multiple" name="00N40000001V9wA" title="Product Interest" class="span9" size="5">
<option value="API">API</option>
**[other options hidden for privacy]**
</select><br>
</div>
<div class="span6 pull-left">
<label for="00N40000001V8Yl" class="span3" style="position:relative; top:-1.2em;">Background Notes:</label>
<textarea id="notes" name="00N40000001V8Yl" type="text" wrap="soft" class="span9"></textarea><br>
</div>
</div>
<div class="clearfix"><br /></div>
<div class="span12 offset3">
<div class="span10 pull-right">
<label for="lead_source" class="span8 pull-left">Check here to be contacted by *** for a demonstration.</label>
<input id="demonstration" type="checkbox" name="lead_source" class="span1 pull-left" value="Web w/Demo Request"></input>
</div>
<div class="span10 pull-right">
<label for="00N400000023QE0" class="span8 pull-left">Check here if you have a timeline for this project.</label>
<input id="timeline" type="checkbox" name="00N400000023QE0" class="span1 pull-left" value="Confirmed"></input>
</div>
<div class="span10 pull-right">
<label for="00N400000023QE5" class="span8 pull-left">Check here if you have purchase authority for this project.</label>
<input id="purchaseAuthority" type="checkbox" name="00N400000023QE5" class="span1 pull-left" value="Confirmed"></input>
</div>
</div>
<div class="clearfix"><br /></div>
<div class="row-fluid">
<div class="span9 pull-right offset2">
<div class="span8">
<?php
require_once('recaptcha/recaptchalib.php');
$publickey = "xxxxxxxxxxxxx"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?><br />
</div>
</div>
</div>
<input type="hidden" name="lead_source" value="Web" />
<input type="hidden" name="00N4000000231kf" value="Web Inquiry" />
<div class="span10 offset1 pull-right">
<input type="submit" name="ctl00$ctl00$MainContent$mainContentHolder$btnSubmit" value="Submit Inquiry" class="btn btn-primary span3 pull-right" />
</div>
</form>
這是contactFormConfirm.php代碼的PHP代碼捲曲:
<?php
ob_start();
session_start();
include_once('[path-to]/recaptcha/recaptchalib.php');
//Recaptcha Settings
$publickey = "xxxxxxxxx"; // you got this from the signup page
$privatekey = "xxxxxxxxx";
//curl method posting
//extract data from the post
extract($_POST);
if (isset($submit)){
$ok = 1;
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$ok = 0;
}
if ($ok){
//set POST variables
$url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
$fields = array(
'oid'=>urlencode($oid),
'retURL'=>urlencode($retURL),
'first_name'=>urlencode($first_name),
'last_name'=>urlencode($last_name),
'title'=>urlencode($title),
'email'=>urlencode($email),
'phone'=>urlencode($phone),
'00N4000000231ne'=>urlencode($profile),
'company'=>urlencode($company),
'country'=>urlencode($country),
'address'=>urlencode($address),
'city'=>urlencode($city),
'state'=>urlencode($state),
'zip'=>urlencode($zip),
'00N40000001V9wA'=>urlencode($productInterest),
'00N40000001V8Yl'=>urlencode($notes),
'lead_source'=>urlencode($demonstration),
'00N400000023QE0'=>urlencode($timeline),
'00N400000023QE5'=>urlencode($purchaseAuthority)
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//print_r($fields_string);
//open 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($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
} //if ok
else {
echo "<h4>Sorry - Invalid Captcha </h4>";
}
} //if submit.
?>
嗨,我建議你在這個鏈接中使用google recaptcha api:[link](http://www.google.com/recaptcha)它有足夠的文檔。此外,我建議你最後使用PRG模式 - 後重定向獲取模式[鏈接](http://en.wikipedia.org/wiki/Post/Redirect/Get),也請考慮使用2個祕密問題,而不是captcha。第一個問題是一個圖像(例如:用他的迷你圖像問奧巴馬),第二個問題是邏輯問題(例如:白色或海洋顏色的對面?)這是更安全的我認爲,因爲一些機器人可以解決驗證碼,但機器人可以不以合乎邏輯的方式考慮... – 2013-03-11 18:50:44
感謝您的建議。我將不得不考慮一些這些。與此同時,我確實與另一位開發人員合作提出瞭解決方案。我會盡快發佈答案。 – cschneider27 2013-03-12 11:30:41