Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/09/2016, 04:11
rafaxusirati
 
Fecha de Ingreso: julio-2010
Ubicación: Cerca Sitges (Barcelona)
Mensajes: 98
Antigüedad: 13 años, 10 meses
Puntos: 4
error al redirigir formulario con recaptcha

Hola a todos.

Me gustaría que este formulario recoja unos datos (nombre, email...) , se valide con recaptcha y pase la información al archivo 1f_ok.php para que lo suba a la BD.

Comentar que el recaptcha lo realiza bien, pero al validar el formulario no carga la información a la BD.

Mucha gracias.


Formulario

Código HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
<title>How to Integrate Google “No CAPTCHA reCAPTCHA” on Your Website</title>
  </head>
  <body>


<?php
 
// coge la librería recaptcha
require_once "../recaptchalib.php";


// tu clave secreta
$secret = "XXXXXXXXXXXXXXXXXXXXX";
 
// respuesta vacía
$response = null;
 
// comprueba la clave secreta
$reCaptcha = new ReCaptcha($secret);


// si se detecta la respuesta como enviada
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse(
        $_SERVER["REMOTE_ADDR"],
        $_POST["g-recaptcha-response"]
    );
}
 ?>


<?php
      if ($response != null && $response->success) {
        echo "<script>alert('Formulario enviado'); location.href='1f_ok.php'</script>";
      } else {
    ?>


 
<form id="new_item_post" class="fm" method="post" action="<? $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" name="procedim" onSubmit="MM_validateForm('nombre','mailcontacto');return document.MM_returnValue" ondblclick="Submit_seguro(this)">
 
      <label for="nombre">Nombre:</label>
      <input name="nombre" required><br />
 
      <label for="mailcontacto">Email:</label>
      <input name="mailcontacto" type="email" required><br />
 
      <div class="g-recaptcha" data-sitekey="XXXXXXXXXXXXXXXXXXXXXX"></div>
 
      <input type="submit" value="Submit" />

    </form>



<?php } ?>

 
    <!--js-->
    <script src='https://www.google.com/recaptcha/api.js'></script>



  </body>
</html>

archivo que procesa la información recibida del formulario 1f_ok.php

Código HTML:
<?php require_once('../Connections/contactos.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
mysql_select_db($database_contactos, $contactos);
$query_Recordset1 = "SELECT * FROM contactos";
$Recordset1 = mysql_query($query_Recordset1, $contactos) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
 
 
 
<?
$db=mysql_connect("dbxxxxxxxx","dbxxxxxx","xxxxx",$db);
    mysql_select_db("dbxxxxxxxx",$db);
 
$nombre=$_POST[nombre];
     $apellido=$_POST[apellido];
     $ciudad=$_POST[ciudad];
     $comunidad=$_POST[comunidad];
        $nombre_usuario=$_POST[nombre_usuario];
    $password=$_POST[password];
    $mailcontacto=$_POST[mailcontacto];
    $mail=$_POST[mail];
    $telefono=$_POST[telefono];
    $telefono2=$_POST[telefono2];
    $provincia=$_POST[provincia];
    $Pais=$_POST[Pais];
    $clave=$_POST[clave];
    $foto1 = $_FILES['foto1']['name'];
    $ip=$_SERVER['REMOTE_ADDR'];
    $prefijo = substr(md5(uniqid(rand())),0,10);
 
 
$uniqueID = substr(md5(uniqid(rand())),0,10);
$foto1=$uniqueID.".".substr($foto1,-3);
 
 
// "directorio" es el directorio donde vas a subir la imagen.
mysql_query("insert into contactos( foto1 , foto2 ,  foto3 ,  foto4 ,  foto5 , nombre_usuario , password , mail , mailcontacto , telefono , telefono2 , nombre , apellido , comunidad , ciudad , provincia , clave , ip )
values('/imagenes/_spain_$foto1','$foto2/datos internos/fotos/ico_sin_foto.gif','$foto3/datos internos/fotos/ico_sin_foto.gif','$foto4/datos internos/fotos/ico_sin_foto.gif','$foto5/datos internos/fotos/ico_sin_foto.gif','$nombre_usuario','$password','$mail','$mailcontacto','$telefono','$telefono2','$nombre','$apellido','$comunidad','$ciudad','$provincia','$clave','$ip')",$db) or die("La clave introducida, ya existe. Elige otra");  
 
//ahora subamos la imagen, "directorio" es el directorio donde la vas a subir.
$copy = copy($_FILES['foto1']['tmp_name'], "../imagenes/_spain_".$foto1);
?>
 
 
 
  </div>
  <!-- end #container -->
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>