Required Fields Validation Help
Posted: Wed Jul 07, 2010 9:15 am
Solved.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?
$source = "Janova Pre-Registration";
$fname = $_REQUEST['first_name'];
$lname = $_REQUEST['last_name'];
$email = $_REQUEST['email'];
$company = $_REQUEST['company'];
$phone = $_REQUEST['phone_number'];
$description = $fname." ".$lname." has pre-registered. Contact him at: ".$email." or at: ".$phone;
//they filled out every field on the form
if (isset($fname) && isset($lname) && isset($email) && isset($email) && isset($company) && isset($phone))
{
echo "Thank you for pre-registering!";
add_to_salesforce($source, $name, $name, $email, $company, "", "", "", $phone, $description, "");
function add_to_salesforce($source, $fname, $lname, $email, $company, $city, $state, $zip, $phone, $description, $street = "")
{
//set POST variables
$url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
$fields = array(
'last_name'=>urlencode($fname),
'first_name'=>urlencode($lname),
'street'=>urlencode($street),
'city'=>urlencode($city),
'state'=>urlencode($state),
'zip'=>urlencode($zip),
'company'=>urlencode($company),
'description'=>urlencode($description),
'email'=>urlencode($email),
'phone'=>urlencode($phone),
'mycustomefieldid' => urlencode($source), // custom field
'oid' => '00DA0000000HgSQ', // insert with your id
'retURL' => urlencode('http://www.janova.us'), // sending this just in case
'debug' => '1',
'debugEmail' => urlencode("brian.lusenhop@janova.us"), // your debugging email
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($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);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
}
}
else //they haven't completed the whole form
echo "You must fill out the entire form before submitting it. Please go back and try again.";
?>