dqstti8945 2014-02-17 21:21
浏览 43
已采纳

salesforce Web2Lead上的cURL验证

I am trying to implement a validation process within the php wrapper for the new web to lead form (salesforce).

The lead gets submitted automatically and completely ignores the validation process.

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"]);}

Here is the full php code:

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

?>
  • 写回答

1条回答 默认 最新

  • dongzaocheng3214 2014-08-30 20:51
    关注

    Well, completely redeveloped a framework that allows me to do such a thing.

    If anyone wants a salesforce web2lead which can easily be connected with any type of form:

    https://github.com/jagmitg/Salesforce-Web2lead

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果