Required Fields Validation Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Starzgoalie30
Forum Newbie
Posts: 3
Joined: Wed Jul 07, 2010 9:07 am

Required Fields Validation Help

Post by Starzgoalie30 »

Solved.
Last edited by Starzgoalie30 on Wed Jul 07, 2010 10:17 am, edited 1 time in total.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Required Fields Validation Help

Post by Jade »

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

Post by Starzgoalie30 »

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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Required Fields Validation Help

Post by AbraCadaver »

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

Post by Starzgoalie30 »

Perfect. That did it. Thanks!
Post Reply