2017-11-28 1 views
0

この問題があります。私はPHPが含まれているブートストラップフォームを作成し、フォームが満たされ、successfuly私は別のページ(.html)にリダイレクトする必要が送信された場合、メッセージを表示する代わりに。フォームを記入してから、別のページにリダイレクトするには

これは、フォームのためのPHPページです:

<?php 
/* 
* CONFIGURE EVERYTHING HERE 
*/ 

// an email address that will be in the From field of the email. 
$from = '[email protected]'; 

// an email address that will receive the email with the output of the form 
$sendTo = '[email protected]'; 

// subject of the email 
$subject = 'Nová zpráva z Vašeho webu'; 

// form field names and their translations. 
// array variable name => Text to appear in the email 
$fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 
'Phone', 'email' => 'Email', 'message' => 'Message'); 

// message that will be displayed when everything is OK :) 
$okMessage = 'Děkuji! Vaše zpráva byla úspěšně odeslána. '; 

// If something goes wrong, we will display this message. 
$errorMessage = 'Omlouvám se, ale došlo k nečekaně chybě. Zkuste to prosím 
později.'; 

/* 
* LET'S DO THE SENDING 
*/ 

// if you are not debugging and don't need error reporting, turn this off by 
error_reporting(0); 
error_reporting(E_ALL & ~E_NOTICE); 

try 
{ 

if(count($_POST) == 0) throw new \Exception('Form is empty'); 

$emailText = "You have a new message from your contact form\n=============================\n"; 

foreach ($_POST as $key => $value) { 
    // If the field exists in the $fields array, include it in the email 
    if (isset($fields[$key])) { 
     $emailText .= "$fields[$key]: $value\n"; 
    } 
} 

// All the neccessary headers for the email. 
$headers = array('Content-Type: text/plain; charset="UTF-8";', 
    'From: ' . $from, 
    'Reply-To: ' . $from, 
    'Return-Path: ' . $from, 
); 

// Send email 
mail($sendTo, $subject, $emailText, implode("\n", $headers)); 

$responseArray = array('type' => 'success', 'message' => $okMessage); 
} 
catch (\Exception $e) 
{ 
    $responseArray = array('type' => 'danger', 'message' => $errorMessage); 
} 


// if requested by AJAX request return JSON response 
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && 
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { 
$encoded = json_encode($responseArray); 

header('Content-Type: application/json'); 

echo $encoded; 
} 
// else just display the message 
else { 
    echo $responseArray['message']; 
} 

そして、ここでは、フォームのHTMLです:

 <form id="contact-form" method="post" action="contact.php"> 

     <div class="messages"></div> 

     <div class="controls"> 

      <div class="row"> 
       <div class="col-md-6"> 
        <div class="form-group"> 
         <label for="form_name">Jméno *</label> 
         <input id="form_name" type="text" name="name" class="form-control" placeholder="Vaše křestní jméno *" required="required" data-error="Firstname is required."> 
         <div class="help-block with-errors"></div> 
        </div> 
       </div> 
       <div class="col-md-6"> 
        <div class="form-group"> 
         <label for="form_lastname">Příjmení *</label> 
         <input id="form_lastname" type="text" name="surname" class="form-control" placeholder="Vaše příjmení *" required="required" data-error="Lastname is required."> 
         <div class="help-block with-errors"></div> 
        </div> 
       </div> 
      </div> 
      <div class="row"> 
       <div class="col-md-6"> 
        <div class="form-group"> 
         <label for="form_email">Email *</label> 
         <input id="form_email" type="email" name="email" class="form-control" placeholder="Váš platný email *" required="required" data-error="Valid email is required."> 
         <div class="help-block with-errors"></div> 
        </div> 
       </div> 
       <div class="col-md-6"> 
        <div class="form-group"> 
         <label for="form_phone">Telefon</label> 
         <input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Váš telefon"> 
         <div class="help-block with-errors"></div> 
        </div> 
       </div> 
      </div> 
      <div class="row"> 
       <div class="col-md-12"> 
        <div class="form-group"> 
         <label for="form_message">Vaše zpráva *</label> 
         <textarea id="form_message" name="message" class="form-control" placeholder="Vaše zpráva *" rows="4" required="required" data-error="Please,leave us a message."></textarea> 
         <div class="help-block with-errors"></div> 
        </div> 
        <br> 
       </div> 
       <div class="col-md-12"> 
        <input type="submit" class="odeslat" value="Odeslat"> 
       </div> 
      </div> 
      <div class="row"> 
       <div class="col-md-12"> 
        <br><p class="text-muted"><strong>*</strong> Tyto pole jsou povinná.</p> 
       </div> 
      </div> 
     </div> 

</form>  

uはplsはそれだけでは表示されませんので、私はそれを修正することができますメッセージ? ありがとう

+1

ルックのhttp:/ /php.net/manual/en/function.header.phpと、ページをリダイレクトするために "Redirect"ヘッダーを使用する方法 –

+0

あなたのコードには開封の '

'コンテンツがありません。あなたがaction = ""値を宣言すると、そのページに行き、見つけたphpを実行します(そして、あなたの投稿されたphpコードが存在すると思います)。処理の終わりに、@ KanujBhatnagarヘッダーコメントを使用して、他のページにユーザーを送ります。 – Nic3500

+0

ええ、オープニングは、ここに閉じ込められていない、申し訳ありません。 – Shade

答えて

0

真の場合、このエコーを示しており、文は、偽の場合にはそのようないくつか示されていない場合は、端部Aに書くことができます - へ>

if(!$ejecutar) 
    { 
    echo "whatever you want"; 
    } 
    else 
    { 
    echo "Whatever you want<br><a href='index.php'>Volver</a>"; 
    } 
関連する問題