简体   繁体   中英

Confirmation page not appearing after submitting the form

I'm new to programming and have made a HTML form which collects data from customers and then saves it in a database ( That's working) The only two parts I'm stuck with is the confirmation page should show a page which says thank you message but right now it goes straight to the home page.

secondly there is a Facebook tracker coding which doesn't seem to be executing I don't know why.

Please could anyone help me ?

Coding for the index page:

<!DOCTYPE html>
    <html>
    <head>
        <title>University of Salford -</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale = 1.0,user-scalable=no, maximum-scale=1.0" />
        <link href="css/style.css" rel="stylesheet"/>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

        <!-- Add HTML 5 vaildation for older browser -->
        <script src="js/forms/modernizr-custom.js" type="text/javascript"></script> 
        <script src="js/forms/polyfiller.js" type="text/javascript"></script> 
        <script src="js/forms/validation.js" type="text/javascript"></script>
    </head>

    <body>
        <div id="headerImg"><img alt="header" src="images/salfordlogo.png"/></div>
        <div id="intro">Welcome to the University of Salford</div>
        <div class="para">
            <ul>
                <li>We welcome over 3000 international students per year from over 100 countries.</li>
                <li>Our presence at MediaCityUK offers invaluable employability enhancing experience to our students across all disciplines.</li>
                <li>To find out what we can offer you, why not come along to meet us in your country over the coming months.</li>
                <li>Please fill in your details below to get more information about our courses and generous scholarship scheme.</li>
            </ul>
        </div>

        <form action="process.php" name="form" id="form" >
            <input type="text" name="firstName" id="firstName" placeholder="First Name" required="required"/>
            <input type="text" name="surname" id="surname" placeholder="Family Name" required="required"/>
            <input type="text" name="dob" id="dob" placeholder="DOB (01/01/88)" required="required"/>
                <select name="nationality">
                <option value="">Nationality</option>
                <option value="Emirati">Emirati</option>
                <option value="Ghanaian">Ghanaian</option>
                <option value="Indian">Indian</option>
                <option value="Iranian">Iranian</option>
                <option value="Malaysian">Malaysian</option>
                <option value="Nigerian">Nigerian</option>
                <option value="Omani">Omani</option>
                <option value="Pakistani">Pakistani</option>
                <option value="Saudi">Saudi</option>
                <option value="Sri Lankan">Sri Lankan</option>
               </select>
            <input type="email" name="email" id="email" placeholder="E-Mail" required="required"/>
            <select name="areaCode" id="areaCode">
                <option value="">Area Code</option>
                <!--<option value="0044">+44 (UK)</option>-->
                <option value="00233">+233 (GH)</option>
                <option value="0091">+91 (IN)</option>
                <option value="0098">+98 (IR)</option>
                <option value="0060">+60 (MY)</option>
                <option value="00234">+234 (NG)</option>
                <option value="00968">+968 (OM)</option>
                <option value="0092">+92 (PK)</option>
                <option value="00966">+966 (SA)</option>
                <option value="0094">+94 (LK)</option>
                <option value="00971">+971 (AE)</option>
            </select>
            <input type="tel" id="mobile" name="mobile" placeholder="Mobile Number" required="required"/>
            <input type="submit" value="Submit"/>

        </form>
        <div id="footer"><img alt="header" src="images/salfordheader.png"/></div>
    </body>
    </html>

Coding for the process page

<?php
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);

    //Start SMS API
    //STEP 1: Configure SMS text and then input bitly link for confirm.php
    require_once '../admin/lib/SmsApi/SmsApi.php';

    $sendSms  = new SmsApi();

    $config = parse_ini_file("config/config.ini");

    $body="Free Msg: \nHi [NAME], thank you for your interest in Salford. Click the link for more details http://bit.ly/salfordman ";

    //End SMS API

    //Connect to the mysql Db $con = 
    //mysql_connect($config['host'], $config['username'], $config['password']);

    try{
        $con = new PDO('mysql:host='.$config['host'].";dbname=".$config['database'].";charset=utf8",$config['username'],$config['password']);
    } catch (PDOException $e){
          header("Location: confirm.php?success=false");
        exit;
    }

    $con->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);



    //Select table to insert incoming data to. The tabel name is define in 
    //config.ini table = "{table}" mysql_select_db($config['database'],$con);

    //check if the any of the get Value have data otherwise show error

    foreach ($_GET as $value) {
         if($value==""){
            header("Location: confirm.php?success=false");
            exit;
         };

}
        //STEP 2: Perform Find/Replace or add in corresponding fields
        //User data fields from form in index file
        $firstName =$_GET['firstName'];
        $surname =$_GET['surname'];
        $dob =$_GET['dob'];
        $nationality =$_GET['nationality'];
        $email =$_GET['email'];
        $areaCode = $_GET['areaCode'];
        $mobile =$_GET['mobile'];

      //NEW MAIL VALIDATION NO NEED TO TOUCH!!!!!!! 
      if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            header("Location: confirm.php?success=false");
            exit;
        }

     //build Mysql query   
        $preparedQuery = $con->prepare("INSERT INTO salford (firstName,surname,dob,nationality,email,areaCode,mobile)
          VALUES (:firstName,:surname,:dob,:nationality,:email,:areaCode,:mobile)");

        $result = $preparedQuery->execute(array(
         ':firstName' => $firstName,
         ':surname'  => $surname,
         ':dob' => $dob,
         'nationality' => $nationality,
         ':email' => $email,
         'areaCode' => $areaCode,
         'mobile' => $mobile
     ));

    $con = null;

    if (!$result){

        //error page 
            header("Location: confirm.php?success=false&type=2");
                exit;
            }else{

            header("Location: http://educate.netmuk.com/salford/minisite");

        //Replace placeholder with dynamic text;
            $body = str_replace("[NAME]", $fullname, $body);

        //Check if leading 0 is present, for the area code
            if(preg_match("/^0/",$mobile)){
                $msisdn = preg_replace("/^0/", $areacode, $mobile); 
            }else{
                $msisdn =$areacode.$mobile;
            }

//build api sms query 
//below block commented by steve. switched to use iGate class
/*$urlQuery = "?body=".urlencode($body)."&msisdn=".$msisdn."&oadc=cccu";

$ch = curl_init();
    curl_setopt_array($ch, array(
    CURLOPT_URL => $config['smsApi'].$urlQuery,
    CURLOPT_RETURNTRANSFER=> TRUE   
));

curl_exec($ch);
curl_close($ch);*/ 




$sendSms->addMessage(
    array('msisdn'=> $msisdn,
        //Add content here
     '      message'=>  $body
)); 

//Set Sender Here
    $sendSms->setSender('Salford')->send();


//$iGateService->sendSMS returns TRUE on success, but we do nothing with it here
    }
?>

Coding for the confirm page which has the Facebook tracker and also the thank you message

 <!DOCTYPE html>
    <html>
        <head>
            <title>Salford</title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale = 1.0,user-scalable=no, maximum-scale=1.0" />
            <link href="css/style.css" rel="stylesheet"/>
        </head>
        <body>
            <div id="headerImg"><img alt="header" src="images/salfordlogo.png"/></div>

            <?php if($_GET['success']=="true"):?>
                <div id="intro">Submitted!</div>    
                <div>
                    Thank you, we will be in touch shortly
                </div>

            <?php else:?>
                <div>
                    There was an error, Please try again in a few moments.
                </div>

            <?php endif;?>

      <script type="text/javascript">
    var fb_param = {};
    fb_param.pixel_id = '6018025148480';
    fb_param.value = '0.00';
    fb_param.currency = 'GBP';
    (function(){
      var fpw = document.createElement('script');
      fpw.async = true;
      fpw.src = '//connect.facebook.net/en_US/fp.js';
      var ref = document.getElementsByTagName('script')[0];
      ref.parentNode.insertBefore(fpw, ref);
    })();
    </script>
    <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/offsite_event.php?id=6018025148480&amp;value=0&amp;currency=GBP" /></noscript>
                      </body>

    </html>

You don't have a link where to be redirected after all the code is processed(in the Coding for the process page), You only have redirection if appears an error. So, if everything works fine, at the end of the file, there should be a redirection code like this:

header("Location: confirm.php?success=true");

So, add this code exactly before ?> in the procession page!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM