Required Fields Validation Help
Moderator: General Moderators
-
Starzgoalie30
- Forum Newbie
- Posts: 3
- Joined: Wed Jul 07, 2010 9:07 am
Required Fields Validation Help
Solved.
Last edited by Starzgoalie30 on Wed Jul 07, 2010 10:17 am, edited 1 time in total.
Re: Required Fields Validation Help
Before they're registered you just need to check if the variables have been set. If they haven't then nothing was entered into the form.
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.";
?>
-
Starzgoalie30
- Forum Newbie
- Posts: 3
- Joined: Wed Jul 07, 2010 9:07 am
Re: Required Fields Validation Help
When I try that though, if I only enter a first name and leave everything blank I still get the "Thank you for pre-registering" response.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Required Fields Validation Help
Don't use isset() they will always be set. Use !empty()
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
Starzgoalie30
- Forum Newbie
- Posts: 3
- Joined: Wed Jul 07, 2010 9:07 am
Re: Required Fields Validation Help
Perfect. That did it. Thanks!