2016-10-22 37 views
0

我試圖顯示一個警告框,說消息發送確定,但由於某種原因,我沒有看到消息。我確實有人說要檢查驗證碼。我究竟做錯了什麼?所有的代碼都在我的index.php文件中。所有if如果在開始時試圖避免重新提交表單。 另外,我如何設計警示框?我試過使用Bootbox。 Js但沒有運氣。PHP js提醒消息,當表單發送好

<?php 
$message['message'] = ""; 
if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['submit'])) { 


    if (isset($_POST['g-recaptcha-response']) && ($_POST["g-recaptcha-response"] != '')) { 

     $url = 'https://www.google.com/recaptcha/api/siteverify'; 
     $privatekey = "--secretKey--"; 

     $response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']); 
     $data = json_decode($response); 

     if (isset($data->success) AND $data->success==true) { 

      $to = "[email protected]"; 
      $email = $_POST['email']; 
      $name = $_POST['name']; 
      $subject = $_POST['asunto']; 
      $subject2 = 'Copia de: '.$_POST['asunto']; 
      $message = $name . " " . "escribio lo siguiente:" . "\n\n" . $_POST['message']; 
      $message2 = "Le enviamos una copia de su mensaje " . $name . "\n\n" . $_POST['message']; 
      $headers = "From:" . $email; 
      $headers2 = "From:" . $to; 
      mail($to,$subject,$message,$headers); 
      mail($email,$subject2,$message2,$headers2); 
      //echo "La consulta se envió correctamente. Gracias! " . $name . ", lo contactaremos a la brevedad."; 
      echo '<script type="text/javascript">alert("El mensaje se envió correctamente. Muchas gracias!");</script>'; 
      //Back to the web 
      header('Location: index.php'); 

     } 

     } else { 
      echo '<script type="text/javascript">alert("Por favor tildar el captcha!");</script>'; 
      //$_SESSION['form'] = filter_input_array(INPUT_POST); 

    } 
} 

?> 

形式:

<div class="col-md-4 to-animate"> 
    <h3 class="section-title">Escribinos</h3> 
    <form class="contact-form" action="" method="post" id="form"> 
     <div class="form-group"> 
      <label for="name" class="sr-only">Nombre</label> 
      <input type="name" class="form-control" name="name" id="name" placeholder="Nombre y Apellido" required title="Por favor ingrese su nombre y apellido" value="<?php echo (isset($_POST['name']) ? htmlspecialchars($_POST['name']) : ''); ?>" /> 
     </div> 
     <div class="form-group"> 
      <label for="asunto" class="sr-only">Asunto</label> 
      <input type="asunto" class="form-control" name="asunto" id="asunto" placeholder="Asunto" required title="Por favor ingrese el asunto" value="<?php echo (isset($_POST['asunto']) ? htmlspecialchars($_POST['asunto']) : ''); ?>" /> 
     </div> 
     <div class="form-group"> 
      <label for="email" class="sr-only">Email</label> 
      <input type="email" class="form-control" name="email" id="email" placeholder="Email" required title="Por favor ingrese un mail" value="<?php echo (isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''); ?>" /> 
     </div> 
     <div class="form-group"> 
      <label for="message" class="sr-only">Mensaje</label> 
      <textarea class="form-control" id="message" name="message" rows="7" placeholder="Mensaje" required title="Por favor ingrese un mensaje mayor a 10 caractéres."><?php echo (isset($_POST['message']) ? htmlspecialchars($_POST['message']) : ''); ?></textarea> 
     </div> 
     <div class="form-group"> 
      <input type="submit" name="submit" id="btn-submit" class="btn btn-send-message btn-md" value="ENVIAR"> 
     </div> 
     <div class="g-recaptcha" data-sitekey="--Sitekey--" data-callback="callback"></div> 
    </form> 
</div> 

回答

0

不知道該代碼的其餘部分,或者如果這是問題 - 但你不應該在「如果」 statetement使用「AND」 - 它應該是:

if (isset($data->success) && $data->success==true) {... 
0

去除

header('Location: index.php'); 

顯示消息。不要問我爲什麼。