2014-02-17 24 views
0

我正在嘗試在新的Web的php包裝器中實現一個驗證過程以引導窗體(salesforce)。salesforce上的cURL驗證Web2Lead

鉛被自動提交併完全忽略驗證過程。

if (empty($_POST["first_name"])) 
    {$firstNameErr = "Name is required";} 
else 
    {$first_name = test_input($_POST["first_name"]);} 

if (empty($_POST["last_name"])) 
    {$lastNameErr = "Email is required";} 
else 
    {$last_name = test_input($_POST["last_name"]);} 

if (empty($_POST["phone"])) 
    {$phoneErr = "";} 
else 
{$phone = test_input($_POST["phone"]);} 

if (empty($_POST["email"])) 
    {$emailErr = "";} 
else 
    {$email = test_input($_POST["email"]);} 

if (empty($_POST["company"])) 
    {$companyNameErr = "Gender is required";} 
else 
    {$company = test_input($_POST["company"]);} 

以下是完整的PHP代碼:

<?php 

//Initialize the $query_string variable for later use 
$query_string = ""; 
$firstNameErr = $lastNameErr = $phoneErr = $emailErr = $companyNameErr = ""; 
$first_name = $last_name = $phone = $email = $company = ""; 


//If there are POST variables 
if ($_POST) { 

//Initialize the $kv array for later use 
$kv = array(); 

//For each POST variable as $name_of_input_field => $value_of_input_field 
foreach ($_POST as $key => $value) { 

//Set array element for each POST variable (ie. first_name=Arsham) 
$kv[] = stripslashes($key)."=".stripslashes($value); 

    if (empty($_POST["first_name"])) 
    {$firstNameErr = "Name is required";} 
    else 
    {$first_name = test_input($_POST["first_name"]);} 

    if (empty($_POST["last_name"])) 
    {$lastNameErr = "Email is required";} 
    else 
    {$last_name = test_input($_POST["last_name"]);} 

    if (empty($_POST["phone"])) 
    {$phoneErr = "";} 
    else 
    {$phone = test_input($_POST["phone"]);} 

    if (empty($_POST["email"])) 
    {$emailErr = "";} 
    else 
    {$email = test_input($_POST["email"]);} 

    if (empty($_POST["company"])) 
    {$companyNameErr = "Gender is required";} 
    else 
    {$company = test_input($_POST["company"]);} 

} 


//Create a query string with join function separted by & 
$query_string = join("&", $kv); 
} 
//Check to see if cURL is installed ... 
if (!function_exists('curl_init')){ 
die('Sorry cURL is not installed!'); 
} 

//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); 

//Set some settings that make it all work :) 
curl_setopt($ch, CURLOPT_HEADER, FALSE); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 

//Execute SalesForce web to lead PHP cURL 
$result = curl_exec($ch); 

//close cURL connection 
curl_close($ch); 

?> 

回答