0

インデックス ページの自分のページにフォームがあります。最初にフォームを送信すると (ブラウザーを開いた後)、PHP スクリプトがメールを送信し、4 秒後に自動的にインデックスにリダイレクトする「感謝ページ」にリダイレクトします。フォームを送信すると、PHP スクリプトはメールを送信しますが、「感謝ページ」にリダイレクトせず、ブラウザは入力されたフォームのインデックス ページにとどまります。

スクリプトのどこに問題やエラーがあるのか​​ わかりません。

あなたが私を助けてくれるなら、私はとても幸せです、それは私のプロジェクトの最後の問題です.

<?php
ob_start( );
include('includes/config.php'); 
if(isset($_POST['Email_Orderer_Form'])) {
$headers = "From: xy@xy.cz\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=utf-8\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Return-Path: info@xy.cz\n";
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "xy@xy.cz, ".$_POST['Email_Orderer_Form']."";  // This email address will recieve the data of form.html
$email_subject = "Rekapitulace objednávky";  // This would be the subject of email that you will recieved
$White_PHP = $_POST['checkboxWhite'];
$White_Velikost_PHP = $_POST['White_Velikost_Form'];
$White_Ks_PHP = $_POST['White_Ks_Form'];
$Black_PHP = $_POST['checkboxBlack'];
$Black_Velikost_PHP = $_POST['Black_Velikost_Form'];
$Black_Ks_PHP = $_POST['Black_Ks_Form'];
$Jmeno_PHP = $_POST['Jmeno_Form'];
$Prijmeni_PHP = $_POST['Prijmeni_Form'];
$Ulice_PHP = $_POST['Ulice_Form'];
$Cislo_Popisne_PHP = $_POST['Cislo_Popisne_Form'];
$Mesto_PHP = $_POST['Mesto_Form'];
$PSC_PHP = $_POST['PSC_Form'];
$Email_Orderer_PHP = $_POST['Email_Orderer_Form'];
$Telefon_PHP = $_POST['Telefon_Form'];
$Komentar_PHP = $_POST['Komentar_Form'];
$Zpusob_Platby_PHP = $_POST['Zpusob_Platby'];
$total_PHP = $_POST['total'];
$q = mysql_query("SELECT ID from objednavky ORDER BY ID DESC LIMIT 1");
$row = mysql_fetch_object($q);
$IDN = $row->ID;
$IDN = $IDN+1;
function clean_text($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$Stav = "New";
$White_PHP = mysql_real_escape_string($White_PHP);
$White_Velikost_PHP = mysql_real_escape_string($White_Velikost_PHP);
$White_Ks_PHP = mysql_real_escape_string($White_Ks_PHP);
$Black_PHP = mysql_real_escape_string($Black_PHP);
$Black_Velikost_PHP = mysql_real_escape_string($Black_Velikost_PHP);
$Black_Ks_PHP = mysql_real_escape_string($Black_Ks_PHP);
$Jmeno_PHP = mysql_real_escape_string($Jmeno_PHP);
$Prijmeni_PHP = mysql_real_escape_string($Prijmeni_PHP);
$Ulice_PHP = mysql_real_escape_string($Ulice_PHP);
$Cislo_Popisne_PHP = mysql_real_escape_string($Cislo_Popisne_PHP);
$Mesto_PHP = mysql_real_escape_string($Mesto_PHP);
$PSC_PHP = mysql_real_escape_string($PSC_PHP);
$Email_Orderer_PHP = mysql_real_escape_string($Email_Orderer_PHP);
$Telefon_PHP = mysql_real_escape_string($Telefon_PHP);
$Komentar_PHP = mysql_real_escape_string($Komentar_PHP);
$Zpusob_Platby_MYSQL = mysql_real_escape_string($Zpusob_Platby_MYSQL);
$total_PHP = mysql_real_escape_string($total_PHP);
if (($_POST['checkboxWhite'] == 'Bílé tričko') && ($_POST['checkboxBlack'] == 'Černé tričko')) {
    $email_message .= "Dobrý den,...\n\n";  
    $email_message .= "Rekapitulace vaší objednávky\n\n";   
    $email_message .= "Tričko 1: ".clean_text($White_PHP)."\n";
    $email_message .= "Velikost trička: ".clean_text($White_Velikost_PHP)."\n";
    $email_message .= "Počet kusů: ".clean_text($White_Ks_PHP)."\n\n";  
    $email_message .= "Tričko 2: ".clean_text($Black_PHP)."\n";
    $email_message .= "Velikost trička: ".clean_text($Black_Velikost_PHP)."\n";
    $email_message .= "Počet kusů: ".clean_text($Black_Ks_PHP)."\n\n";  
    if ($Zpusob_Platby_PHP == "Ucet")
    {
        $email_message .= "Zvolili jste způsob platby: Platba předem na účet\n";
        $email_message .= "Účet: XY\n";
        $email_message .= "Kód banky: XY\n";
        $email_message .= "Variabilní symbol: 15010".$IDN."\n\n";   
        $email_message .= "Celková cena objednávky: ".clean_text($total_PHP)."\n\n";    
        $email_message .= "Ihned po přijetí platby bude Vaše tričko odesláni na zadanou adresu.\n\n";       
        $Zpusob_Platby_MYSQL = "Na účet - VS: 15010".$IDN."";   
    }
    if ($Zpusob_Platby_PHP == "Dobirka") {
        $email_message .= "Způsob platby: Dobírka\n\n";     
        $email_message .= "Celková cena objednávky: ".clean_text($total_PHP)."\n\n";        
        $email_message .= "Vaše objednávka byla odeslána na zadanou adresu.\n";     
        $Zpusob_Platby_MYSQL = "Dobírka";
    }
    $email_message .= "Rekapitulace Vašich údajů\n\n";
    $email_message .= "Jméno: ".clean_text($Jmeno_PHP)."\n";
    $email_message .= "Příjmení: ".clean_text($Prijmeni_PHP)."\n";
    $email_message .= "Ulice: ".clean_text($Ulice_PHP)."\n";
    $email_message .= "Číslo popisné: ".clean_text($Cislo_Popisne_PHP)."\n";
    $email_message .= "Město: ".clean_text($Mesto_PHP)."\n";
    $email_message .= "PSČ: ".clean_text($PSC_PHP)."\n";
    $email_message .= "Email: ".clean_text($Email_Orderer_PHP)."\n";
    $email_message .= "Telefon: ".clean_text($Telefon_PHP)."\n";
    $email_message .= "Komentář: ".clean_text($Komentar_PHP)."\n\n";
    $email_message .= "V případě jakéhokoli problému...";
    mysql_query("INSERT INTO objednavky (Tricko1,Tricko1Velikost,Tricko1Ks,Tricko2,Tricko2Velikost,Tricko2Ks,Platba,Cena,Jmeno,Prijmeni,Ulice,CisloPopisne,Mesto,PSC,Email,Telefon,Zprava,Stav) 
                VALUES ('$White_PHP','$White_Velikost_PHP','$White_Ks_PHP','$Black_PHP','$Black_Velikost_PHP','$Black_Ks_PHP','$Zpusob_Platby_MYSQL','$total_PHP','$Jmeno_PHP','$Prijmeni_PHP','$Ulice_PHP','$Cislo_Popisne_PHP','$Mesto_PHP','$PSC_PHP','$Email_Orderer_PHP','$Telefon_PHP','$Komentar_PHP','$Stav')")or die(mysql_error());
}
else {
if ($_POST['checkboxWhite'] == 'Bílé tričko') {
    $Black_PHP = "-";
    $Black_Velikost_PHP = "-";
    $Black_Ks_PHP = "-";
    $email_message .= "Dobrý den,..\n\n";
    $email_message .= "Rekapitulace vaší objednávky\n\n";
    $email_message .= "Tričko: ".clean_text($White_PHP)."\n";
    $email_message .= "Velikost trička: ".clean_text($White_Velikost_PHP)."\n";
    $email_message .= "Počet kusů: ".clean_text($White_Ks_PHP)."\n\n";
    if ($Zpusob_Platby_PHP == "Ucet")
    {
        $email_message .= "Zvolili jste způsob platby: Platba předem na účet\n";
        $email_message .= "Účet: XY\n";
        $email_message .= "Kód banky: XY\n";
        $email_message .= "Variabilní symbol: 15010".$IDN."\n\n";
        $email_message .= "Celková cena objednávky: ".clean_text($total_PHP)."\n\n";
        $email_message .= "Ihned po přijetí platby bude Vaše tričko odesláni na zadanou adresu.\n\n";
        $Zpusob_Platby_MYSQL = "Na účet - VS: 15010".$IDN."";   
    }
    if ($Zpusob_Platby_PHP == "Dobirka") {
        $email_message .= "Způsob platby: Dobírka\n\n";
        $email_message .= "Celková cena objednávky: ".clean_text($total_PHP)."\n\n";
        $email_message .= "Vaše objednávka byla odeslána na zadanou adresu.\n";
        $Zpusob_Platby_MYSQL = "Dobírka";
    }
    $email_message .= "Rekapitulace Vašich údajů\n\n";
    $email_message .= "Jméno: ".clean_text($Jmeno_PHP)."\n";
    $email_message .= "Příjmení: ".clean_text($Prijmeni_PHP)."\n";
    $email_message .= "Ulice: ".clean_text($Ulice_PHP)."\n";
    $email_message .= "Číslo popisné: ".clean_text($Cislo_Popisne_PHP)."\n";
    $email_message .= "Město: ".clean_text($Mesto_PHP)."\n";
    $email_message .= "PSČ: ".clean_text($PSC_PHP)."\n";
    $email_message .= "Email: ".clean_text($Email_Orderer_PHP)."\n";
    $email_message .= "Telefon: ".clean_text($Telefon_PHP)."\n";
    $email_message .= "Komentář: ".clean_text($Komentar_PHP)."\n\n";
    $email_message .= "V případě jakéhokoli problému...";
    mysql_query("INSERT INTO objednavky (Tricko1,Tricko1Velikost,Tricko1Ks,Tricko2,Tricko2Velikost,Tricko2Ks,Platba,Cena,Jmeno,Prijmeni,Ulice,CisloPopisne,Mesto,PSC,Email,Telefon,Zprava,Stav) 
                VALUES ('$White_PHP','$White_Velikost_PHP','$White_Ks_PHP','$Black_PHP','$Black_Velikost_PHP','$Black_Ks_PHP','$Zpusob_Platby_MYSQL','$total_PHP','$Jmeno_PHP','$Prijmeni_PHP','$Ulice_PHP','$Cislo_Popisne_PHP','$Mesto_PHP','$PSC_PHP','$Email_Orderer_PHP','$Telefon_PHP','$Komentar_PHP','$Stav')")or die(mysql_error());
}
if ($_POST['checkboxBlack'] == 'Černé tričko') {
    $White_PHP = "-";
    $White_Velikost_PHP = "-";
    $White_Ks_PHP = "-";
    $email_message .= "Dobrý den,...\n\n";
    $email_message .= "Rekapitulace vaší objednávky\n\n";
    $email_message .= "Tričko: ".clean_text($Black_PHP)."\n";
    $email_message .= "Velikost trička: ".clean_text($Black_Velikost_PHP)."\n";
    $email_message .= "Počet kusů: ".clean_text($Black_Ks_PHP)."\n\n";
    if ($Zpusob_Platby_PHP == "Ucet")
    {
        $email_message .= "Zvolili jste způsob platby: Platba předem na účet\n";
        $email_message .= "Účet: XY\n";
        $email_message .= "Kód banky: XY\n";
        $email_message .= "Variabilní symbol: 15010".$IDN."\n\n";
        $email_message .= "Celková cena objednávky: ".clean_text($total_PHP)."\n\n";
        $email_message .= "Ihned po přijetí platby bude Vaše tričko odesláni na zadanou adresu.\n\n";
        $Zpusob_Platby_MYSQL = "Na účet - VS: 15010".$IDN."";   
    }
    if ($Zpusob_Platby_PHP == "Dobirka") {
        $email_message .= "Způsob platby: Dobírka\n\n";
        $email_message .= "Celková cena objednávky: ".clean_text($total_PHP)."\n\n";
        $email_message .= "Vaše objednávka byla odeslána na zadanou adresu.\n";
        $Zpusob_Platby_MYSQL = "Dobírka";
    }
    $email_message .= "Rekapitulace Vašich údajů\n\n";
    $email_message .= "Jméno: ".clean_text($Jmeno_PHP)."\n";
    $email_message .= "Příjmení: ".clean_text($Prijmeni_PHP)."\n";
    $email_message .= "Ulice: ".clean_text($Ulice_PHP)."\n";
    $email_message .= "Číslo popisné: ".clean_text($Cislo_Popisne_PHP)."\n";
    $email_message .= "Město: ".clean_text($Mesto_PHP)."\n";
    $email_message .= "PSČ: ".clean_text($PSC_PHP)."\n";
    $email_message .= "Email: ".clean_text($Email_Orderer_PHP)."\n";
    $email_message .= "Telefon: ".clean_text($Telefon_PHP)."\n";
    $email_message .= "Komentář: ".clean_text($Komentar_PHP)."\n\n";
    $email_message .= "V případě jakéhokoli problému...";
    mysql_query("INSERT INTO objednavky (Tricko1,Tricko1Velikost,Tricko1Ks,Tricko2,Tricko2Velikost,Tricko2Ks,Platba,Cena,Jmeno,Prijmeni,Ulice,CisloPopisne,Mesto,PSC,Email,Telefon,Zprava,Stav) 
                VALUES ('$White_PHP','$White_Velikost_PHP','$White_Ks_PHP','$Black_PHP','$Black_Velikost_PHP','$Black_Ks_PHP','$Zpusob_Platby_MYSQL','$total_PHP','$Jmeno_PHP','$Prijmeni_PHP','$Ulice_PHP','$Cislo_Popisne_PHP','$Mesto_PHP','$PSC_PHP','$Email_Orderer_PHP','$Telefon_PHP','$Komentar_PHP','$Stav')")or die(mysql_error());
}
mysql_Close();
}
@mail($email_to, $email_subject, $email_message, $headers);
}
unset($_POST);
ob_end_clean( ); 
header('Location: http://www.myurl.cz/thankspage.php');
exit;
?>

この制御 js スクリプトで問題が発生する可能性はありますか?

    $(document).ready(function() {
  // when a form is submited, get its data and validate the fields
  $('#Order_Form').submit(function() {
    // gets field values    
    var Jmeno_JS = $(this).find('input[name="Jmeno_Form"]');
    var Prijmeni_JS = $(this).find('input[name="Prijmeni_Form"]');
    var Ulice_JS = $(this).find('input[name="Ulice_Form"]');
    var Cislo_Popisne_JS = $(this).find('input[name="Cislo_Popisne_Form"]');
    var Mesto_JS = $(this).find('input[name="Mesto_Form"]');
    var PSC_JS = $(this).find('input[name="PSC_Form"]');
    var Email_Orderer_JS = $(this).find('input[name="Email_Orderer_Form"]');
    var Zpusob_Platby_JS = $(this).find('select[name="Zpusob_Platby"]');


    // remove class "error" from al elements
    // sets a variable "error" used to submit or no the form
    $('*').removeClass('error');
    var error = 0;
    var regx = /^([a-z0-9_\-\.])+\@([a-z0-9_\-\.])+\.([a-z]{2,4})$/i;   // regexp for e-mail

          /* Validate the fields (adds class "error" to invalid fields and set error=1) */
    // check "name"

    if(Jmeno_JS.val().length<2){
      Jmeno_JS.addClass(' error');
      error = 1;
    }

    if(Prijmeni_JS.val().length<2){
      Prijmeni_JS.addClass(' error');
      error = 1;
    }
    if(Ulice_JS.val().length<2){
      Ulice_JS.addClass(' error');
      error = 1;
    }
    if(Cislo_Popisne_JS.val().length<2){
      Cislo_Popisne_JS.addClass(' error');
      error = 1;
    }
    if(Mesto_JS.val().length<2){
      Mesto_JS.addClass(' error');
      error = 1;
    }
    if(PSC_JS.val().length<5){
      PSC_JS.addClass(' error');
      error = 1;
    }
    // check "email"
    if(!regx.test(Email_Orderer_JS.val())){
      Email_Orderer_JS.addClass(' error');
      error = 1;
    }
    if(Zpusob_Platby_JS.val()==Zpusob_Platby_JS.find('option:first').val()){
      Zpusob_Platby_JS.addClass('error');
      error = 1;
    }
    // if error is 0, serialize form data and send the data string to server
    // else alert a message
    if(error==0) {
      var srl = $(this).serialize();

      $.ajax({
        type: 'post',
        url: 'order_send.php',
        data: srl,
        beforeSend: function() {
          // before send the request, displays a "Loading..." messaj in the element where the response will be placed
          $('#resp').html('Loading...');
        },
        timeout: 10000,        // sets timeout for the request (10 seconds)
        error: function(xhr, status, error) {window.location = "order_send.php"},     // alert a message in case of error
        success: function(response) {
          $('#resp').html(response);
        }
      });
    }
    else { }

    return false;      // necesary to not open the page when form is submited
  });
});
4

2 に答える 2

1

実行が成功した後にリダイレクトする解決策を見つけるために OP と会話した後window.location = "thankspage.php"、コントローラー ファイルで成功応答として使用する必要がありました。

于 2013-09-18T15:54:46.773 に答える
0

これを試して:

exit(header('Location: http://www.myurl.cz/thankspage.php'));

また

die(header('Location: http://www.myurl.cz/thankspage.php'));
于 2013-09-18T14:43:48.230 に答える