Ver Mensaje Individual
  #4 (permalink)  
Antiguo 22/08/2014, 19:45
mortisdj
 
Fecha de Ingreso: mayo-2014
Ubicación: Valencia
Mensajes: 63
Antigüedad: 10 años
Puntos: 0
Respuesta: Validacion recaptcha

Ya lo he solucionado de la siguiente forma...

Código:
<?php require_once('Connections/conexion.php'); ?>
<?php require_once('includes/funciones.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_conexion, $conexion);
//$query_DatosCentros = "SELECT * FROM tblcentro ORDER BY tblcentro.refProvincia ASC,  tblcentro.strLocalidad ASC , strNombre ASC";
$query_DatosCentros = "SELECT tblcentro.*,tblprovincias.provincia, tblprovincias.id FROM
tblcentro
Inner Join tblprovincias ON tblcentro.refProvincia = tblprovincias.id ORDER BY tblprovincias.provincia ASC, tblcentro.strLocalidad ASC, tblcentro.strNombre ASC";
$DatosCentros = mysql_query($query_DatosCentros, $conexion) or die(mysql_error());
$row_DatosCentros = mysql_fetch_assoc($DatosCentros);
$totalRows_DatosCentros = mysql_num_rows($DatosCentros);

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

require_once('recaptchalib.php');
 
// Get a key from http://recaptcha.net/api/getkey
$publickey = "XXX";
$privatekey = "XXX";
 
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
 
# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);
 
        if ($resp->is_valid) {
			
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "formulario")) {
  $insertSQL = sprintf("INSERT INTO tblusuarios (strNombre, strApellidos, strEspecialidad, intCentro,  strEmail, intTelefono, strMensaje, intOrigen) VALUES (%s, %s, %s, %s, %s, %s, %s, 0)",
                       GetSQLValueString($_POST['strNombre'], "text"),
                       GetSQLValueString($_POST['strApellidos'], "text"),
                       GetSQLValueString($_POST['strEspecialidad'], "text"),
                       GetSQLValueString($_POST['intCentro'], "int"),        
                       GetSQLValueString($_POST['strEmail'], "text"),
                       GetSQLValueString($_POST['intTelefono'], "text"),
                       GetSQLValueString($_POST['strMensaje'], "text"));

  mysql_select_db($database_conexion, $conexion);
  $Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());

  $insertGoTo = "profesores-registro-ok.php";
  /*if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }*/

  $query_DatosCentros2 = "SELECT strNombre, strLocalidad, tblprovincias.provincia, tblprovincias.id FROM tblcentro Inner Join tblprovincias ON tblcentro.refProvincia = tblprovincias.id WHERE intCentro = '" . $_POST['intCentro'] . "'";
  $DatosCentros2 = mysql_query($query_DatosCentros2, $conexion) or die(mysql_error());
  $row_DatosCentros2 = mysql_fetch_assoc($DatosCentros2);
  $totalRows_DatosCentros2 = mysql_num_rows($DatosCentros2);

  header(sprintf("Location: %s", $insertGoTo));
	$asunto = 'Formulario de Contacto Enviado desde profesores registrados';
	$destinatario = '[email protected]';
    $mensaje = "Hola admin,<br />";
    $mensaje .= "se ha enviado un formulario de contacto desde profesores resgistrados con lo siguientes datos:<br /><br />";    $mensaje .= "- Nombre: ".$_POST['strNombre']."<br />";
    $mensaje .= "- Apellidos: ".$_POST['strApellidos']."<br />";
    $mensaje .= "- Especialidad: ".$_POST['strEspecialidad']."<br />";
    $mensaje .= "- Provincia: ".$row_DatosCentros2['provincia'] ."<br />"; 
	$mensaje .= "- Localidad: ".$row_DatosCentros2['strLocalidad'] ."<br />";
    $mensaje .= "- Centro: ".$row_DatosCentros2['strNombre'] ."<br />";
    $mensaje .= "- Telefono: ".$_POST['intTelefono']."<br />";
    $mensaje .= "- Email: ".$_POST['strEmail']."<br />";
    $mensaje .= "- Mensaje: ".nl2br($_POST['strMensaje'])."<br /><br />";	
	EnviarCorreoHTML($destinatario,$asunto,utf8_decode($mensaje));
}
        } else {
                # set the error code so that we can display it
				 $error = $resp->error;
        }
}
?>
Y en el formulario...

Código:
                        <br><br>Mensaje:<br><textarea class="seleccionarea" id="mensajeregistro" name="strMensaje" placeholder="Mensaje:" rows="5" onClick="javascript:  borrarmensaje();"></textarea>
<div id="errorregistromensaje" class="ocultar texto-error">* Debe escribir un Mensaje</div>
<br><br>
                    
                    <?php
                    echo recaptcha_get_html($publickey, $error); ?> 
                        <div class="clear"></div>
                        <div class="btns">