2016-10-22 2 views
0

메시지를 보냈다는 경고 상자를 표시하려고하는데 어떤 이유로 메시지가 표시되지 않습니다. captcha를 확인하라는 말을 듣게됩니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 모든 코드는 내 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'); 
를 제거한 후

메시지가 나타납니다. 왜 나 한테 묻지 마.

관련 문제