#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    PHP form valitaion and submit


    I have been working on this form that seems to manage validating the right way, but I need it to submit afterwards and can't figure out how to do that how I want. I'm still new with PHP and could use some help.
    I'm trying to make the form submit similar to this one, with no need for javascript.
    allstatescartransport.com/car-transport.html

    Here is my validation script so far. It's a little bulky, so any help is appreciated

    PHP Code:
    <?php

    if($_POST)
    {
    $first_name $_POST['first_name']; 
    $last_name $_POST['last_name'];  
    $phone $_POST['phone'];
    $email $_POST['email'];
    $year1 $_POST['year1'];
    $make1 $_POST['make1']; 
    $model1 $_POST['model1'];  
    $vehicle_type_id1 $_POST['vehicle_type_id1']; 
    $pickup_city $_POST['pickup_city']; 
    $pickup_state_code $_POST['pickup_state_code'];
    $dropoff_city $_POST['dropoff_city']; 
    $dropoff_state_code $_POST['dropoff_state_code'];  
    $vehicle_runs $_POST['vehicle_runs'];
    $ship_via_id $_POST['ship_via_id'];
    $estimated_ship_date $_POST['estimated_ship_date'];


    // First Name
    if (preg_match ("/ ^ [A-Za-z -] {3.20} $ /", $ first_name))
     {
           
    $valid_first_name=$first_name;
     }
    else
    {  
        
    $error_first_name='Enter valid First Name.';  
    }
    // Last Name
    if (preg_match ("/ ^ [A-Za-z -] {3.20} $ /", $ last_name))
     {
           
    $valid_last_name=$last_name;
     }
    else
    {  
        
    $error_last_name='Enter valid Last Name.';  
    }
    // Phone
    if (preg_match ("/ ^ [0-9 -] {7.20} $ /", $ phone))
     {
           
    $valid_phone=$phone;
     }
    else
    {  
        
    $error_phone='Enter valid Phone Number.';  
    }
    // Email 
    if (preg_match ("/ ^ [a-zA-Z0-9._-] + @ [a-zA-Z0-9._-] + \. ([a-zA-Z] {2,4}) $ / ", $ email))
     {
           
    $valid_email=$email
     }
    else
    {  
        
    $error_email='Enter valid Email.';  
    }
    // Year
    if (preg_match("/^[0-9 -]{2,20}$/",$year1))
     {
           
    $valid_year1=$year1;
     }
    else
    {  
    $error_year1='Enter valid Vehicle Year.';  }

    // Make

    if (preg_match ("/ ^ [A-Za-z0-9 -] {2.25} $ /", $ make1))
     {
          
    $valid_make1=$make1;
     }
    else
    {  
        
    $error_make1='Enter valid Vehicle Make.';  
    }
    // Model

    if (preg_match ("/ ^ [A-Za-z0-9 -] {2.25} $ /", $ model1))
     {
          
    $valid_model1=$model1;
     }
    else
    {  
        
    $error_model1='Enter valid Vehicle Model.';  
    }

    // Vehicle Type
    if ($vehicle_type_id1==00)
     {
            
    $error_vehicle_type_id1='Select Vehicle Type'
     }
    else
    {  
    $valid_vehicle_type_id1=$vehicle_type_id1;
        
    }
    // Pickup City
    if (preg_match ("/ ^ [A-Za-z0-9 -] {3.20} $ /", $ pickup_city))
     {
           
    $valid_pickup_city=$pickup_city;
     }
    else
    {  
        
    $error_pickup_city='Enter valid Pickup City.';  
    }
    // Pickup state
    if ($pickup_state_code==00)
     {
            
    $error_pickup_state_code='Select Pickup State.'
     }
    else
    {  
    $valid_pickup_state_code=$pickup_state_code;
        
    }
    // Dropoff City
    if (preg_match ("/ ^ [A-Za-z0-9 -] {3.20} $ /", $ dropoff_city))
     {
           
    $valid_dropoff_city=$dropoff_city;
     }
    else
    {  
        
    $error_dropoff_city='Enter valid Dropoff City.';  
    }
    // Dropoff state
    if ($dropoff_state_code==00)
     {
            
    $error_dropoff_state_code='Select Dropoff State.'
     }
    else
    {  
    $valid_dropoff_state_code=$dropoff_state_code;
        
    }
    // Vehicle Runs
    if ($vehicle_runs==00)
     {
            
    $error_vehicle_runs='Does your vehicle run?'
     }
    else
    {  
    $valid_vehicle_runs=$vehicle_runs;
        
    }
    // Ship Via
    if ($ship_via_id==00)
     {
            
    $error_ship_via_id='Select how to ship.'
     }
    else
    {  
    $valid_ship_via_id=$ship_via_id;
        
    }
    // Estimated Shipping Date
    if (preg_match("/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/",$estimated_ship_date))
     {
           
    $valid_estimated_ship_date=$estimated_ship_date;
     }
    else
    {  
        
    $error_estimated_ship_date='Enter valid Shipping Date.';  
    }

    ($ 
    Valid_ship_via_id0) && (strlen ($ valid_estimated_ship_date)> 0))
    {}
    {
    post to process.php


    }


    }
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,383
    Rep Power
    594
    1) Please use [ PHP ] tags rather than [ CODE ] tags for PHP. See the sticky at the top of this forum list. Editing your post will help.
    2) I think you are confused between server side (PHP) and client side (browser). When the form is filled in the client clicks the submit button at which point your server validates the data. In other words the form has been submitted. You do not show your form but rather than checking $_POST you should use isset($_POST['Submit']). That code will be executed when the client submits the form.
    3) Validating a form on the server with PHP is necessary but user unfriendly as the user will have to wait for the server to know they entered something wrong and then have to start over. What I do is validate the form with Javascript so the user immediately knows when they have a wrong entry and all the entered data is preserved. On the server side I am less sympathetic with the user because if there is a validation error there (assuming your Javascript is correct) then they must be trying to circumvent validation on the client side. In that case I have no problem issuing an error page and making them start over.
    Last edited by gw1500se; December 5th, 2012 at 01:27 PM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115
    There are a few errors in your script (like spaces between dollarsign and variable)
    Also I would use a different approach than regular expressions to check things like a username. (it is said they consume quite some processing power).
    Give me a minute and I'll post some improvements.

    BTW: You require a form, this script wont do anything without a form.

    -edit: hehe I see GW also posted around the same time
    Last edited by aeternus; December 5th, 2012 at 02:50 PM.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    Also, I tried to change the [ CODE ] tags to [ php ] tags just now and it said that I can't post links, which the link here is an example of what I'm trying!
    here is the form code, it's long and also have the javascript validation in it. I had to dumb down the form because it made the post about 55,000 characters...
    Code:
    <form action="" method="post" name="quoteForm">
    <div class="fieldContainer">
            <span class="err"> <?php echo $error_first_name; ?></span>
              <p><span class="redStar">*</span> First Name:
                <input name="first_name" type="text" required="required" id="first_name" pattern="[A-Za-z -]{3,20}"  value="<?php echo $valid_first_name; ?>" />
              </p>
            </div>
            
            <div class="fieldContainer">
            <span class="err"> <?php echo $error_last_name; ?></span>
              <p><span class="redStar">*</span> Last Name:
                <input name="last_name" type="text" required="required" id="last_name" pattern="[A-Za-z -]{3,20}" value="<?php echo $valid_last_name; ?>" />
                
              </p>
            </div>
            
            <div class="fieldContainer">
            <span class="err"> <?php echo $error_phone; ?></span>
              <p><span class="redStar">*</span> Phone:
                <input name="phone" type="text" required="required" id="phone" pattern="[0-9 -]{7,20}" value="<?php echo $valid_phone; ?>" />
                
              </p>
            </div>
            <span class="err"> <?php echo $error_email; ?></span>
            <div class="fieldContainer">
            
              <p><span class="redStar">*</span> Email:
                <input name="email" type="text" required="required" id="email" pattern="[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})" value="<?php echo $valid_email; ?>" />
                           
              </p>
            </div>
            <br />
            <h4>Vehicle Information:</h4>
            <span class="err"> <?php echo $error_year1; ?></span>
            <div class="fieldContainer">
              <p><span class="redStar">*</span> Year:
                <input name="year1" type="text" required="required" id="year1" pattern="[0-9 -]{2,20}" value="<?php echo $valid_year1; ?>" />
                 
              </p>
            </div>
    
        <script language="JavaScript" type="text/javascript" xml:space="preserve">
    	//<![CDATA[
    	//You should create the validator only after the definition of the HTML form
      var frmvalidator  = new Validator("quoteForm");
     frmvalidator.EnableOnPageErrorDisplaySingleBox();
     frmvalidator.EnableMsgsTogether();
     
      frmvalidator.addValidation("first_name","req","Please enter your First Name");
      frmvalidator.addValidation("first_name","alpha_s","Name can contain alphabetic chars only");
      
      frmvalidator.addValidation("last_name","req","Please enter your Last Name");
      frmvalidator.addValidation("last_name","alpha_s","Name can contain alphabetic chars only");
      
      frmvalidator.addValidation("phone","req","Please enter your Phone Number");
      frmvalidator.addValidation("phone","minlen=10","Please format your phone number correctly");
      
      frmvalidator.addValidation("email","req","Please enter a valid e-mail address");
      frmvalidator.addValidation("email","maxlen=50");
      frmvalidator.addValidation("email","email");
      
      frmvalidator.addValidation("year1","req","Please enter your Vehicle Year");
      frmvalidator.addValidation("year1","num","Vehicle year must be a number");
      
      frmvalidator.addValidation("make1","req","Please enter your Vehicle Make");
      
      frmvalidator.addValidation("model1","req","Please enter your Vehicle Model");
      
      frmvalidator.addValidation("vehicle_type_id1","dontselect=00","Please select your Vehicle Type");
      
      frmvalidator.addValidation("pickup_city","req","Please enter your Vehicle's Pickup City");
      
      frmvalidator.addValidation("pickup_state_code","dontselect=00","Please select your Vehicle's Pickup State");
      
      frmvalidator.addValidation("dropoff_city","req","Please enter your Vehicle's Dropoff City");
      
      frmvalidator.addValidation("dropoff_state_code","dontselect=00","Please select your Vehicle's Dropoff State");
      
      frmvalidator.addValidation("vehicle_runs","dontselect=00","Please select whether the vehicle runs or not");
      
      frmvalidator.addValidation("ship_via_id","dontselect=00","Please select your preferred Shipment Method");
      
      frmvalidator.addValidation("estimated_ship_date","req","Please select your estimated ship date");
    //]]></script> 
        <script type="text/javascript">
    	<? if($_GET['pickup_city'] != "Pickup City"){ ?>
    		document.getElementById('pickup_city').value = "<?php echo $_GET['pickup_city'];?>";
    	<? } ?>
      	document.getElementById('pickup_state_code').value = "<?php echo $_GET['pickup_state_code'];?>";
    	<? if($_GET['dropoff_city'] != "Dropoff City"){ ?>
    	document.getElementById('dropoff_city').value = "<?php echo $_GET['dropoff_city'];?>";
    	<? } ?>
      	document.getElementById('dropoff_state_code').value = "<?php echo $_GET['dropoff_state_code'];?>";
    </script>
    Thank you both!
  8. #5
  9. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115
    Your form action is left empty so in order to make it work you either have to fill in the url of the processing page or include the processing script on the form page itself. Did you have a look at your variables that have a space between the dollar sign and the variablename? You have quite a few of them.

    here a simplified form to get you started (although if you fix the dollarsigns and the form actions you should already be up and running)
    PHP Code:
    <?php

    /**
     * @desc                      simple range function
     * @param   str int int     check if the string has a length within a certain range
     * @return  bool
     */
    function CheckAllowedStringLength($string$min$max){
        if(
    strlen($string) >= $min && strlen($string) <= $max){
            return 
    true;
        }else{
            return 
    false;
        }
    }

    /**
     * check the post data
     */
    $errors = array();

    if(isset(
    $_POST['submit'])){ // make sure the form is submitted
        //check if the values are as expected
        //firstname
        
    if(!empty($_POST['first_name']) // firstname may not be empty
                
    && CheckAllowedStringLength($_POST['first_name'], 320) === true // firstname needs to be between the given range
                
    && ctype_alpha($_POST['first_name'])){ // firstname needs to be alpha characters only
            
                
    $first_name $_POST['first_name']; //passed the test
        
    }else{
                
    $first_name ''// an empty value in case 1 of the above tests failed
                
    $errors[] = 'firstname is left empty or invalid';
        }
        
    //lastname
        //etc
    }

    /**
     *   @desc a simple form to submit. Make sure you fill in the action URL if the php_file is seperate 
     */
    ?>
    <form action="" method="post">
        <input type="text" name="first_name" />
        <input type="submit" name="submit" value="submit" />
    </form>

    <?php
     
    if(isset($_POST['submit'])){
         
    // output some stuff
         
    echo $first_name;
         
    var_dump($errors);
         
     }


    ?>
    Last edited by aeternus; December 5th, 2012 at 02:30 PM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,383
    Rep Power
    594
    I don't know how you tried to use PHP tags but the sticky explains it. Highlight the PHP code, then click the PHP icon.

    It appears you are trying to mix PHP with Javascript. When you go through your logic, keep straight in your mind what is being executed on the client (Javascript) and what is being executed on the server. Neither one knows about the other. Output any PHP HTML that is common to both before and after submit. Use an 'if (isset' block, as I suggested, to output any dependent HTML after the form is submitted along with the processing of the $_POST data (your PHP validation would go here). Then use an 'else' block to output any HTML that is exclusive to before the form is submitted.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    aeternus, thank you for the code sample. I looked through the code on my end and didn't find any spaces, even with a search for "$ " so I don't know why it shows like that in my first post. The code you wrote there does work, but what you say about putting process.php in the form action makes it so it doesn't work anymore. It skips the validation and goes right to processing. If I put it just how you have it and I submit blank it gives back "array(1) { [0]=> string(34) "firstname is left empty or invalid" } " and I don't know if it's supposed to give all that info.

    gw - Thank you for the advice, but I don't understand as much as I would like to with php... I'm about a week in on trying to learn around an already too busy schedule, so it's going a bit slow!
    the javascript has its own validation and doesn't do anything with the php, but they are on the same page. What is supposed to happen is first the form has to pass html5, but if the browser doesn't handle that then to javascript, and if that's disabled then php.


    I appreciate you two helping me and hope to not take up too much more of your time!
  14. #8
  15. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115
    Hi mate,

    I think you mean it skips the javascript validation. (leave that out for now, javascript is pure for aesthetics and not real validation).

    If you fill in the formaction, you ofcourse need to make sure that process.php is the file that validates. So you have 2 file (unlike my script which was an example) form.php and process.php

    The example I gave at the bottom does a var_dump of the errors array (its just an example for testing, so you have some feedback, and yes It should give that feedback, because you filled in a blank or less than 3 or more than 20 characters)

    The biggest thing I think Is to leave javascript out for now (it makes it overcomplicated. make the script work. Use the given clause
    PHP Code:
     if(isset($_POST['submit'])){
        
    // clause

    I have no idea why your code got messed so it showed spaces between the dollar signs. It might be wise to have error reporting on that way you can give us some more detailed feedback on what goes wrong. place this above all your script in development fase
    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    ini_set('display_errors''On');
    ?>
    Last edited by aeternus; December 5th, 2012 at 05:51 PM.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    I'm testing validation in IE9 with security set to max, which disables javascript already. That's really the whole reason for this. People fill out the form wrong and when it posts I get a copy of it in mysql database, but the db that it needs to go into is with jtracker and if it isn't filled out right it doesn't make it in.
    If there's no name it doesn't go in, the date wrong, email address not valid etc... people are really bad about filing things out!
    So I decided on PHP because it's server side and the user can't do anything about it
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    I have something now that works as its own file, but I need to figure out how to do the rest of the stuff I need.
    PHP Code:
    <?php

    if (count($_POST) <= 0)
    {
        exit();
    }

    $aFilters = array(
        
    'first_name' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z- ]{3,20}$/i'),
        ),
        
    'last_name' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z- ]{3,20}$/i'),
        ),
        
    'phone' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[0-9-]{7,20}$/i'),
        ),
        
    'email' => FILTER_VALIDATE_EMAIL,
        
    'year1' => array(
            
    'filter' => FILTER_VALIDATE_INT,
            
    'options' => array('min_range' => 1900'max_range' => 2100),
        ),
        
    'make1' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z0-9 -]{2,25}$/i'),
        ),
        
    'model1' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z0-9 -]{2,25}$/i'),
        ),
        
    'vehicle_type_id1' => array(
            
    'filter' => FILTER_VALIDATE_INT,
            
    'options' => array('min_range' => 1),
        ),
        
    'pickup_city' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z0-9 -]{3,20}$/i'),
        ),
        
    'pickup_state_code' => array(
            
    'filter' => FILTER_VALIDATE_INT,
            
    'options' => array('min_range' => 1),
        ),
        
    'dropoff_city' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z0-9 -]{3,20}$/i'),
        ),
        
    'dropoff_state_code' => array(
            
    'filter' => FILTER_VALIDATE_INT,
            
    'options' => array('min_range' => 1),
        ),
        
    'vehicle_runs' => array(
            
    'filter' => FILTER_VALIDATE_INT,
            
    'options' => array('min_range' => 1),
        ),
        
    'ship_via_id' => array(
            
    'filter' => FILTER_VALIDATE_INT,
            
    'options' => array('min_range' => 1),
        ),
        
    'estimated_ship_date' => array(
            
    'filter' => FILTER_CALLBACK,
            
    'options' => 'strtotime',
        )
    );


    $aFailureNotices = array (
      
    'first_name' => 'Invalid First Name',
      
    'last_name' => 'Invalid Last Name',
      
    'phone' => 'Invalid Phone Number',
      
    'email' => 'Invalid Email Address',
      
    'year1' => 'Invalid Year',
      
    'make1' => 'Invalid Make',
      
    'model1' => 'Invalid Model',
      
    'vehicle_type_id1' => 'Invalid Vehicle Type ID',
      
    'pickup_city' => 'Invalid Pickup City',
      
    'pickup_state_code' => 'Invalid Pickup State Code',
      
    'dropoff_city' => 'Invalid Dropoff City',
      
    'dropoff_state_code' => 'Invalid Dropoff State Code',
      
    'vehicle_runs' => 'Invalid Vehicle Runs option',
      
    'ship_via_id' => 'Invalid Ship Via ID',
      
    'estimated_ship_date' => 'Invalid Estimate Ship Date',
    );


    // Do the work now.
    // Filter the input array
    $filtered filter_input_array(INPUT_POST$aFilters);

    function 
    isEmpty($s)
    {
        return empty(
    $s);
    }

    // Pick out the empty ones (null is actually not provided, false is failed)
    $aBadEntries array_filter($filtered'isEmpty');

    // Get a collection of error messages
    $aErrorMessages array_intersect_key($aFailureNotices$aBadEntries);

    if (!empty(
    $aErrorMessages))
    {
        print(
    'The following errors occurred: ');
        foreach (
    $aErrorMessages AS $error)
        {
            print 
    PHP_EOL $error
        }
    }
    else
    {
        echo 
    "success";


    ?>
    I've tested it with only the curl and mysql code, and it only posts the the mysql database. I think there may be a problem with curl?
    -edit : the curl seems to be functioning, it just took about 5 times as long to post as usual.
    PHP Code:
    <?php

    $ch 
    curl_init();
    curl_setopt($chCURLOPT_URL"jtracker.com/lead_post.php");
    curl_setopt($chCURLOPT_POST1);
    curl_setopt($chCURLOPT_TIMEOUT100);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_POSTFIELDShttp_build_query($_POST));
    $data curl_exec($ch);
    curl_close($ch);

    mysql_connect("localhost, "user", "password") or die("Connection Failed");
    mysql_select_db("
    database")or die("Connection Failed");
    $referrer = $_POST['referrer'];
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $vehicle_type_id1 = $_POST['vehicle_type_id1'];
    $pickup_city = $_POST['pickup_city'];
    $pickup_state_code = $_POST['pickup_state_code'];
    $dropoff_city = $_POST['dropoff_city'];
    $dropoff_state_code = $_POST['dropoff_state_code'];
    $vehicle_runs = $_POST['vehicle_runs'];
    $ship_via_id = $_POST['ship_via_id'];
    $estimated_ship_date = $_POST['estimated_ship_date'];
    $query = "INSERT INTO Boat_Shipping(referrer,first_name,last_name,email,phone,vehicle_type_id1,pickup_city,pickup_state_code,dropoff_city,dropoff_state_code,vehicle_runs,ship_via_id,estimated_ship_date)VALUES('$referrer','$first_name','$last_name','$email','$phone','$vehicle_type_id1','$pickup_city','$pickup_state_code','$dropoff_city','$dropoff_state_code','$vehicle_runs','$ship_via_id','$estimated_ship_date')";
    if(mysql_query(
    $query)){
    echo "
    Your information is being processedPlease wait.";}
    else{
    echo "
    Database Error";}




    mysql_close();




    ?>
    <script type="
    text/javascript"> if (!window.mstag) mstag = {loadTag : function(){},time : (new Date()).getTime()};</script> <script id="mstag_tops" type="text/javascript" src="//flex.atdmt.com/mstag/site/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/mstag.js"></script> <script type="text/javascript"> mstag.loadTag("analytics", {dedup:"1",domainId:"1570529",type:"1",actionid:"104890"})</script> <noscript> <iframe src="//flex.atdmt.com/mstag/tag/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/analytics.html?dedup=1&domainId=1570529&type=1&actionid=104890" frameborder="0" scrolling="no" width="1" height="1" style="visibility:hidden;display:none"> </iframe> </noscript>

    <meta http-equiv="REFRESH" content="1;url=/thankyou.php">
    <
    center><h1>Please <a href="/thankyou.php">Click Here</a> if your Thank You page does not load.</h1></center>
    Last edited by ott; December 7th, 2012 at 07:39 AM. Reason: because of edits
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    I've had some help with the issue and have removed the validation code from the page with the form so the form action posts to process.php as in the code above, then process.php does this.
    PHP Code:

    <?php

    if (count($_POST) <= 0)
    {
        exit();
    }

    $aFilters = array(
        
    'first_name' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z- ]{3,20}$/i'),
        ),
        
    'last_name' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z- ]{3,20}$/i'),
        ),
        
    'phone' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[0-9-]{7,20}$/i'),
        ),
        
    'email' => FILTER_VALIDATE_EMAIL,
        
    'year1' => array(
            
    'filter' => FILTER_VALIDATE_INT,
            
    'options' => array('min_range' => 1900'max_range' => 2100),
        ),
        
    'make1' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z0-9 -]{2,25}$/i'),
        ),
        
    'model1' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z0-9 -]{2,25}$/i'),
        ),
        
    'vehicle_type_id1' => array(
            
    'filter' => FILTER_VALIDATE_INT,
            
    'options' => array('min_range' => 1),
        ),
        
    'pickup_city' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z0-9 -]{3,20}$/i'),
        ),
        
    'pickup_state_code' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-zA-Z- ]{2}$/i'),
        ),
        
    'dropoff_city' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-z0-9 -]{3,20}$/i'),
        ),
        
    'dropoff_state_code' => array(
            
    'filter' => FILTER_VALIDATE_REGEXP,
            
    'options' => array('regexp' => '/^[a-zA-Z- ]{2}$/i'),
        ),
        
    'vehicle_runs' => array(
            
    'filter' => FILTER_VALIDATE_INT,
            
    'options' => array('min_range' => 1),
        ),
        
    'ship_via_id' => array(
            
    'filter' => FILTER_VALIDATE_INT,
            
    'options' => array('min_range' => 1),
        ),
        
    'estimated_ship_date' => array(
            
    'filter' => FILTER_CALLBACK,
            
    'options' => 'strtotime',
        )
    );


    $aFailureNotices = array (
    'first_name' => 'Invalid First Name',
    'last_name' => 'Invalid Last Name',
    'phone' => 'Invalid Phone Number',
    'email' => 'Invalid Email Address',
    'year1' => 'Invalid Year',
    'make1' => 'Invalid Make',
    'model1' => 'Invalid Model',
    'vehicle_type_id1' => 'Invalid Vehicle Type ID',
    'pickup_city' => 'Invalid Pickup City',
    'pickup_state_code' => 'Invalid Pickup State Code',
    'dropoff_city' => 'Invalid Dropoff City',
    'dropoff_state_code' => 'Invalid Dropoff State Code',
    'vehicle_runs' => 'Invalid Vehicle Runs option',
    'ship_via_id' => 'Invalid Ship Via ID',
    'estimated_ship_date' => 'Invalid Estimate Ship Date',
    );


    // Do the work now.
    // Filter the input array
    $filtered filter_input_array(INPUT_POST$aFilters);

    function 
    isEmpty($s)
    {
        return empty(
    $s);
    }

    // Pick out the empty ones (null is actually not provided, false is failed)
    $aBadEntries array_filter($filtered'isEmpty');

    // Get a collection of error messages
    $aErrorMessages array_intersect_key($aFailureNotices$aBadEntries);

    if (!empty(
    $aErrorMessages))
    {
        print(
    'The following errors occurred: ');
        foreach (
    $aErrorMessages AS $error)
        {
            print 
    PHP_EOL $error;
            echo 
    '<br>';
        }

    echo 
    '<br><center><table width="75%"><tr><td valign="top"><form action="" method="post" name="quoteForm">
    <input type="hidden" name="broker_id" value="33d1918e06fd9a56a257ab44154e54e2" />
    <input type="hidden" name="referrer" value="BPPC" />
    <input type="hidden" name="post_back" value="http://www.shipyourcarnow.com/thankyou.php" />
    <input type="hidden" name="company_name" value="SYCNB" />
    <div class="column-1 left">
    <h4>Contact Information:</h4>

    <div class="fieldContainer">

    <p><span class="redStar">*</span> First Name:
    <input name="first_name" type="text" required="required" id="first_name" pattern="[A-Za-z -]{3,20}" value="" />
    </p>
    </div>

    <div class="fieldContainer">
    <p><span class="redStar">*</span> Last Name:
    <input name="last_name" type="text" required="required" id="last_name" pattern="[A-Za-z -]{3,20}" value="" />

    </p>
    </div>

    <div class="fieldContainer">
    <p><span class="redStar">*</span> Phone:
    <input name="phone" type="text" required="required" id="phone" pattern="[0-9 -]{7,20}" value="" />

    </p>
    </div>
    <div class="fieldContainer">
    <p><span class="redStar">*</span> Email:
    <input name="email" type="text" required="required" id="email" pattern="[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})" value="" />
    </p>
    </div>
    <br />
    <h4>Vehicle Information:</h4>
    <div class="fieldContainer">
    <p><span class="redStar">*</span> Year:
    <input name="year1" type="text" required="required" id="year1" pattern="[0-9 -]{2,20}" value="" />

    </p>
    </div>
    <div class="fieldContainer">
    <p><span class="redStar">*</span> Make:
    <input name="make1" type="text" required="required" id="make1" pattern="[A-Za-z0-9 -]{2,25}" value="" />

    </p>
    </div>
    <div class="fieldContainer">
    <p><span class="redStar">*</span> Model:
    <input name="model1" type="text" required="required" id="model1" pattern="[A-Za-z0-9 -]{2,25}" value="" />

    </p>
    </div>
    <div class="fieldContainer">
    <p><span class="redStar">*</span> Vehicle Type:
    <select name="vehicle_type_id1" id="vehicle_type_id1" >
    <option label="Select one" value="00">Select one</option>
    <option label="Coupe" value="21">Coupe</option>
    <option label="Sedan Small" value="1">Sedan Small</option>
    <option label="Sedan Midsize" value="13">Sedan Midsize</option>
    <option label="Sedan Large" value="2">Sedan Large</option>
    <option label="Convertible" value="14">Convertible</option>
    <option label="Pickup Small" value="3">Pickup Small</option>
    <option label="Pickup Crew Cab" value="5">Pickup Crew Cab</option>
    <option label="Pickup Full-size" value="15">Pickup Full-size</option>
    <option label="Pickup Extd. Cab" value="4">Pickup Extd. Cab</option>
    <option label="RV" value="22">RV</option>
    <option label="Dually" value="20">Dually</option>
    <option label="SUV Small" value="6">SUV Small</option>
    <option label="SUV Mid-size" value="7">SUV Mid-size</option>
    <option label="SUV Large" value="8">SUV Large</option>
    <option label="Travel Trailer" value="23">Travel Trailer</option>
    <option label="Van Mini" value="9">Van Mini</option>
    <option label="Van Full-size" value="10">Van Full-size</option>
    <option label="Van Extd. Length" value="16">Van Extd. Length</option>
    <option label="Van Pop-Top" value="18">Van Pop-Top</option>
    <option label="Motorcycle" value="19">Motorcycle</option>
    <option label="Boat" value="12">Boat</option>
    <option label="Other" value="11">Other</option>
    </select>
    </p>
    </div>
    <div class="fieldContainer">
    <p>Vehicle Type, Other:
    <input type="text" name="vehicle_type_other1" id="vehicle_type_other1" value="" style="width:100px;" />
    </p>
    </div>
    </div></td><td valign="top">
    <div class="column left">
    <h4>Pickup Information:</h4>
    <div class="fieldContainer">
    <p><span class="redStar">*</span> City:
    <input name="pickup_city" type="text" required="required" id="pickup_city" pattern="[A-Za-z0-9 -]{3,20}" value="" />
    </p>
    </div>
    <div class="fieldContainer">
    <p><span class="redStar">*</span> State:
    <select name="pickup_state_code" id="pickup_state_code">
    <option label="Select State" value="00">Select State</option>
    <option label="Alabama" value="AL">Alabama</option>
    <option label="Alaska" value="AK">Alaska</option>
    <option label="Arizona" value="AZ">Arizona</option>
    <option label="Arkansas" value="AR">Arkansas</option>
    <option label="California" value="CA">California</option>
    <option label="Colorado" value="CO">Colorado</option>
    <option label="Connecticut" value="CT">Connecticut</option>
    <option label="Delaware" value="DE">Delaware</option>
    <option label="Dist. of Columbia" value="DC">Dist. of Columbia</option>
    <option label="Florida" value="FL">Florida</option>
    <option label="Georgia" value="GA">Georgia</option>
    <option label="Guam" value="GU">Guam</option>
    <option label="Hawaii" value="HI">Hawaii</option>
    <option label="Idaho" value="ID">Idaho</option>
    <option label="Illinois" value="IL">Illinois</option>
    <option label="Indiana" value="IN">Indiana</option>
    <option label="Iowa" value="IA">Iowa</option>
    <option label="Kansas" value="KS">Kansas</option>
    <option label="Kentucky" value="KY">Kentucky</option>
    <option label="Louisiana" value="LA">Louisiana</option>
    <option label="Maine" value="ME">Maine</option>
    <option label="Maryland" value="MD">Maryland</option>
    <option label="Massachusetts" value="MA">Massachusetts</option>
    <option label="Michigan" value="MI">Michigan</option>
    <option label="Minnesota" value="MN">Minnesota</option>
    <option label="Mississippi" value="MS">Mississippi</option>
    <option label="Missouri" value="MO">Missouri</option>
    <option label="Montana" value="MT">Montana</option>
    <option label="Nebraska" value="NE">Nebraska</option>
    <option label="Nevada" value="NV">Nevada</option>
    <option label="New Hampshire" value="NH">New Hampshire</option>
    <option label="New Jersey" value="NJ">New Jersey</option>
    <option label="New Mexico" value="NM">New Mexico</option>
    <option label="New York" value="NY">New York</option>
    <option label="North Carolina" value="NC">North Carolina</option>
    <option label="North Dakota" value="ND">North Dakota</option>
    <option label="Ohio" value="OH">Ohio</option>
    <option label="Oklahoma" value="OK">Oklahoma</option>
    <option label="Oregon" value="OR">Oregon</option>
    <option label="Pennsylvania" value="PA">Pennsylvania</option>
    <option label="Puerto Rico" value="PR">Puerto Rico</option>
    <option label="Rhode Island" value="RI">Rhode Island</option>
    <option label="South Carolina" value="SC">South Carolina</option>
    <option label="South Dakota" value="SD">South Dakota</option>
    <option label="Tennessee" value="TN">Tennessee</option>
    <option label="Texas" value="TX">Texas</option>
    <option label="Utah" value="UT">Utah</option>
    <option label="Vermont" value="VT">Vermont</option>
    <option label="Virgin Islands" value="VI">Virgin Islands</option>
    <option label="Virginia" value="VA">Virginia</option>
    <option label="Washington" value="WA">Washington</option>
    <option label="West Virginia" value="WV">West Virginia</option>
    <option label="Wisconsin" value="WI">Wisconsin</option>
    <option label="Wyoming" value="WY">Wyoming</option>
    <option label="Canada-Province" value="CP">Canada-Province</option>
    <option label="Alberta" value="AB">Alberta</option>
    <option label="British Columbia" value="BC">British Columbia</option>
    <option label="Manitoba" value="MB">Manitoba</option>
    <option label="New Brunswick" value="NB">New Brunswick</option>
    <option label="Newfoundland" value="NL">Newfoundland</option>
    <option label="NW Territories" value="NT">NW Territories</option>
    <option label="Nova Scotia" value="NS">Nova Scotia</option>
    <option label="Nunavut" value="NU">Nunavut</option>
    <option label="Ontario" value="ON">Ontario</option>
    <option label="Prince Edward Isl." value="PE">Prince Edward Isl.</option>
    <option label="Quebec" value="QC">Quebec</option>
    <option label="Saskatchewan" value="SK">Saskatchewan</option>
    <option label="Yukon" value="YT">Yukon</option>
    <option label="Other Countries" value="OC">Other Countries</option>
    </select>
    </p>
    </div>
    <div class="fieldContainer">
    <p>Zip:
    <input type="text" name="pickup_zip" id="pickup_zip" value="" />
    </p>
    </div>

    <br />
    <h4>Dropoff Information:</h4>
    <div class="fieldContainer">
    <p><span class="redStar">*</span> City:
    <input name="dropoff_city" type="text" required="required" id="dropoff_city" pattern="[A-Za-z0-9 -]{3,20}" value="" />
    </p>
    </div>
    <div class="fieldContainer">
    <p><span class="redStar">*</span> State:
    <select name="dropoff_state_code" id="dropoff_state_code">
    <option label="Select State" value="00">Select State</option>
    <option label="Alabama" value="AL">Alabama</option>
    <option label="Alaska" value="AK">Alaska</option>
    <option label="Arizona" value="AZ">Arizona</option>
    <option label="Arkansas" value="AR">Arkansas</option>
    <option label="California" value="CA">California</option>
    <option label="Colorado" value="CO">Colorado</option>
    <option label="Connecticut" value="CT">Connecticut</option>
    <option label="Delaware" value="DE">Delaware</option>
    <option label="Dist. of Columbia" value="DC">Dist. of Columbia</option>
    <option label="Florida" value="FL">Florida</option>
    <option label="Georgia" value="GA">Georgia</option>
    <option label="Guam" value="GU">Guam</option>
    <option label="Hawaii" value="HI">Hawaii</option>
    <option label="Idaho" value="ID">Idaho</option>
    <option label="Illinois" value="IL">Illinois</option>
    <option label="Indiana" value="IN">Indiana</option>
    <option label="Iowa" value="IA">Iowa</option>
    <option label="Kansas" value="KS">Kansas</option>
    <option label="Kentucky" value="KY">Kentucky</option>
    <option label="Louisiana" value="LA">Louisiana</option>
    <option label="Maine" value="ME">Maine</option>
    <option label="Maryland" value="MD">Maryland</option>
    <option label="Massachusetts" value="MA">Massachusetts</option>
    <option label="Michigan" value="MI">Michigan</option>
    <option label="Minnesota" value="MN">Minnesota</option>
    <option label="Mississippi" value="MS">Mississippi</option>
    <option label="Missouri" value="MO">Missouri</option>
    <option label="Montana" value="MT">Montana</option>
    <option label="Nebraska" value="NE">Nebraska</option>
    <option label="Nevada" value="NV">Nevada</option>
    <option label="New Hampshire" value="NH">New Hampshire</option>
    <option label="New Jersey" value="NJ">New Jersey</option>
    <option label="New Mexico" value="NM">New Mexico</option>
    <option label="New York" value="NY">New York</option>
    <option label="North Carolina" value="NC">North Carolina</option>
    <option label="North Dakota" value="ND">North Dakota</option>
    <option label="Ohio" value="OH">Ohio</option>
    <option label="Oklahoma" value="OK">Oklahoma</option>
    <option label="Oregon" value="OR">Oregon</option>
    <option label="Pennsylvania" value="PA">Pennsylvania</option>
    <option label="Puerto Rico" value="PR">Puerto Rico</option>
    <option label="Rhode Island" value="RI">Rhode Island</option>
    <option label="South Carolina" value="SC">South Carolina</option>
    <option label="South Dakota" value="SD">South Dakota</option>
    <option label="Tennessee" value="TN">Tennessee</option>
    <option label="Texas" value="TX">Texas</option>
    <option label="Utah" value="UT">Utah</option>
    <option label="Vermont" value="VT">Vermont</option>
    <option label="Virgin Islands" value="VI">Virgin Islands</option>
    <option label="Virginia" value="VA">Virginia</option>
    <option label="Washington" value="WA">Washington</option>
    <option label="West Virginia" value="WV">West Virginia</option>
    <option label="Wisconsin" value="WI">Wisconsin</option>
    <option label="Wyoming" value="WY">Wyoming</option>
    <option label="Canada-Province" value="CP">Canada-Province</option>
    <option label="Alberta" value="AB">Alberta</option>
    <option label="British Columbia" value="BC">British Columbia</option>
    <option label="Manitoba" value="MB">Manitoba</option>
    <option label="New Brunswick" value="NB">New Brunswick</option>
    <option label="Newfoundland" value="NL">Newfoundland</option>
    <option label="NW Territories" value="NT">NW Territories</option>
    <option label="Nova Scotia" value="NS">Nova Scotia</option>
    <option label="Nunavut" value="NU">Nunavut</option>
    <option label="Ontario" value="ON">Ontario</option>
    <option label="Prince Edward Isl." value="PE">Prince Edward Isl.</option>
    <option label="Quebec" value="QC">Quebec</option>
    <option label="Saskatchewan" value="SK">Saskatchewan</option>
    <option label="Yukon" value="YT">Yukon</option>
    <option label="Other Countries" value="OC">Other Countries</option>
    </select>
    </p>
    </div>
    <div class="fieldContainer">
    <p>Zip:
    <input type="text" name="dropoff_zip" id="dropoff_zip" value="" />
    </p>
    </div>

    <div class="fieldContainer">
    <p><span class="redStar">*</span> Ship Via:
    <select name="ship_via_id" id="ship_via_id">
    <option label="Select one" value="00">Select one</option>
    <option label="Open" value="1">Open</option>
    <option label="Enclosed" value="2">Enclosed</option>
    <option label="Driveaway" value="3">Driveaway</option>
    </select>
    </p>
    </div>
    <div class="fieldContainer">
    <p><span class="redStar">*</span> Est Ship Date:
    <input name="estimated_ship_date" type="text" required="required" id="estimated_ship_date" style="width:80px;" pattern="[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}" />
    </p>
    </div>
    <div style="FONT-STYLE: normal; COLOR: #888888; FONT-WEIGHT: normal; font-size: 11px; margin-left: 105px; margin-top: -10px;">
    MM/DD/YYYY
    </div><br>
    <input type="submit"></td></tr></table></center>'
    ;
    }
    else
    {
        
    $ch curl_init();
    curl_setopt($chCURLOPT_URL"[url="http://www.jtracker.com/lead_post.php"]http://www.jtracker..../lead_post.php"[/url]);
    curl_setopt($chCURLOPT_POST1);
    curl_setopt($chCURLOPT_TIMEOUT100);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_POSTFIELDShttp_build_query($_POST));
    $data curl_exec($ch);
    curl_close($ch);


    mysql_connect("localhost""user""password") or die("Connection Failed");
    mysql_select_db("database")or die("Connection Failed");
    $referrer $_POST['referrer'];
    $first_name $_POST['first_name'];
    $last_name $_POST['last_name'];
    $email $_POST['email'];
    $phone $_POST['phone'];
    $vehicle_type_id1 $_POST['vehicle_type_id1'];
    $pickup_city $_POST['pickup_city'];
    $pickup_state_code $_POST['pickup_state_code'];
    $dropoff_city $_POST['dropoff_city'];
    $dropoff_state_code $_POST['dropoff_state_code'];
    $vehicle_runs $_POST['vehicle_runs'];
    $ship_via_id $_POST['ship_via_id'];
    $estimated_ship_date $_POST['estimated_ship_date'];
    $query "INSERT INTO Boat_Shipping(referrer,first_name,last_name,email,phone,vehicle_type_id1,pickup_city,pickup_state_code,dropoff_city,dropoff_state_code,vehicle_runs,ship_via_id,estimated_ship_date)VALUES('$referrer','$first_name','$last_name','$email','$phone','$vehicle_type_id1','$pickup_city','$pickup_state_code','$dropoff_city','$dropoff_state_code','$vehicle_runs','$ship_via_id','$estimated_ship_date')";
    if(
    mysql_query($query)){
    echo 
    "Your information is being processed. Please wait.";}
    else{
    echo 
    "Database Error";}




    mysql_close();

    echo 
    '<script type="text/javascript"> if (!window.mstag) mstag = {loadTag : function(){},time : (new Date()).getTime()};</script> <script id="mstag_tops" type="text/javascript" src="//flex.atdmt.com/mstag/site/xxxxxxxxxxxxxxxxxxxxxxxxxx/mstag.js"></script> <script type="text/javascript"> mstag.loadTag("analytics", {dedup:"1",domainId:"1570529",type:"1",actionid:"104890"})</script> <noscript> <iframe src="//flex.atdmt.com/mstag/tag/xxxxxxxxxxxxxxxxxxxxxxx/analytics.html?dedup=1&domainId=1570529&type=1&actionid=104890" frameborder="0" scrolling="no" width="1" height="1" style="visibility:hidden;display:none"> </iframe> </noscript>

    <meta http-equiv="REFRESH" content="1;url=/thankyou.php">
    <center><h1>Please <a href="/thankyou.php">Click Here</a> if your Thank You page does not load.</h1></center>'
    ;
    }

    ?>
    Now all I have to do is re-add the form so that they don't have to go back and have it populated with the values that are good. As far as I can tell, it works perfectly for the validate and submit part but don't know if the campaign tracking code works.

IMN logo majestic logo threadwatch logo seochat tools logo