2016-10-22 12 views
0

メッセージが送信されたという警告ボックスを表示しようとしていますが、何らかの理由でメッセージが表示されません。私はキャプチャを確認するように言っている。私は間違って何をしていますか?すべてのコードは私のindex.phpファイルにあります。すべてのifは、フォームを再送信しないようにしようとします。 また、アラートボックスのスタイルを設定するにはどうすればよいですか?私はBootboxを使ってみました。 Jsだが運がない。フォームが送信されたときのPHP jsアラートメッセージok

<?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'); 
を除去した後、

メッセージが表示されます。なぜ私に尋ねないでください。

関連する問題