Foros del Web » Programando para Internet » PHP »

form con dos action

Estas en el tema de form con dos action en el foro de PHP en Foros del Web. tengo un form que ejecuta una funcion: la de insertar datos en una tabla mysql. Pero necesito que ejecute otra funcion, la de verificar un ...
  #1 (permalink)  
Antiguo 28/07/2008, 18:59
Avatar de leskolpykos  
Fecha de Ingreso: junio-2007
Ubicación: Caracas
Mensajes: 96
Antigüedad: 16 años, 10 meses
Puntos: 0
form con dos action

tengo un form que ejecuta una funcion: la de insertar datos en una tabla mysql. Pero necesito que ejecute otra funcion, la de verificar un codigo introducido antes de enviar los datos a la tabla. Como hago para que ejecute las dos órdenes?

Acá tengo el script php

Código PHP:
<?php require_once('../home/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$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;
}
}

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


if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO libro (usuario, email, mensaje) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['usuario'], "text"),
                       
GetSQLValueString($_POST['email'], "text"),
                       
GetSQLValueString($_POST['mensaje'], "text"));

  
mysql_select_db($database_localhost);
  
$Result1 mysql_query($insertSQL) or die(mysql_error());

  
$insertGoTo "test.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>
a ese escript necesito incluirle éste script en alguna parte

Código PHP:
<?php
session_start
();
if (
$_POST['action'] == "checkdata") {
    if (
$_SESSION['tmptxt'] == $_POST['tmptxt']) {
        echo 
"Bienvenido";
    } else {
        echo 
"Intentalo nuevamente";
    }
    exit;
}
?>
se lo incluí al principio y quedó así

Código PHP:
<?php require_once('../home/conexion.php'); ?>
<?php

session_start
();
if (
$_POST['action'] == "checkdata") {
    if (
$_SESSION['tmptxt'] == $_POST['tmptxt']) {
        echo 
"Bienvenido";
    } else {
        echo 
"Intentalo nuevamente";
    }
    exit;
}

if (!
function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$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;
}
}

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


if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO libro (usuario, email, mensaje) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['usuario'], "text"),
                       
GetSQLValueString($_POST['email'], "text"),
                       
GetSQLValueString($_POST['mensaje'], "text"));

  
mysql_select_db($database_localhost);
  
$Result1 mysql_query($insertSQL) or die(mysql_error());

  
$insertGoTo "test.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>
ahora, el formulario, al final están los dos input, obviamente solo se ejecuta una: o ingresa los datos en la tabla o verifica los datos, pero no hace las dos:

Código HTML:
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Usuario:</td>
      <td><input type="text" name="usuario" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Email:</td>
      <td><input type="text" name="email" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Mensaje:</td>
      <td><p>
        <textarea name="mensaje" cols="50" rows="5"></textarea>
      </p>
      <p>
      
      <img src="captcha.php" width="100" height="30" vspace="3"><br>
		  <input name="tmptxt" type="text" size="30"><br>

          
          </p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input name="btget" type="submit" class="boton" value="Insertar registro" /></td>
    </tr>
  </table>
  <input name="action" type="hidden" value="checkdata">
  <input type="hidden" name="MM_insert" value="form1" />
</form> 
¡QUE ESTOY HACIENDO MAL?
__________________
www.luisespectaculo.net el portal de artistas y farándula más grande de Venezuela!

Última edición por leskolpykos; 29/07/2008 a las 09:11
  #2 (permalink)  
Antiguo 28/07/2008, 19:12
Avatar de quinqui  
Fecha de Ingreso: agosto-2004
Ubicación: Chile!
Mensajes: 776
Antigüedad: 19 años, 8 meses
Puntos: 56
Respuesta: form con dos action

Holas leskolpykos

Mira, al agregar el código que chequea, hay una llamada a session_start(), la cual siempre debe ir al principio de tu script (en tu caso queda después de llamar al script conexion.php). La verdad no estoy segura si esto produce error, pero a primeras podría ser por eso...

Ahora, sobre validar, pues yo lo veo bien O_o... Claro que no sé en qué momento llenas el valor de $_SESSION['tmptxt'] con el valor a comparar para la validación...
__________________
pipus.... vieeeeeji plomius!!!
*quinqui site*
  #3 (permalink)  
Antiguo 28/07/2008, 19:31
Avatar de leskolpykos  
Fecha de Ingreso: junio-2007
Ubicación: Caracas
Mensajes: 96
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: form con dos action

Hola quinqui gracias por tu respuesta!

con respecto al session_start() siempre o al menos en los demás form que he trabajado siempre ha estado asi como lo puse en éste y no me ha generado errores o conflictos.

Fijate en el form que hay éstas dos líneas al final:

Código HTML:
<input name="action" type="hidden" value="checkdata">
<input name="MM_insert" type="hidden" value="form1" /> 
es aquí donde está el error!!! solo debería haber una, pero ocurre que si quito la que dice "action" no me verifica el código de seguridad que introduce el usuario pero si me ingresa los datos a la tabla mysql, y si dejo ese pero quito el que dice "MM_insert" me verifica el código de seguridad si es correcto o no, pero no me introduce los datos en la tabla :(

esta linea es la que verifica el código de seguridad if ($_POST['action'] == "checkdata") { y ésta es la que ingresa los datos a la tabla if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

no es posible juntar esas dos líneas?
__________________
www.luisespectaculo.net el portal de artistas y farándula más grande de Venezuela!
  #4 (permalink)  
Antiguo 28/07/2008, 19:33
Avatar de leskolpykos  
Fecha de Ingreso: junio-2007
Ubicación: Caracas
Mensajes: 96
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: form con dos action

respuesta repetida.
__________________
www.luisespectaculo.net el portal de artistas y farándula más grande de Venezuela!

Última edición por leskolpykos; 29/07/2008 a las 09:04 Razón: se envio dos veces la respuesta
  #5 (permalink)  
Antiguo 29/07/2008, 11:12
Avatar de quinqui  
Fecha de Ingreso: agosto-2004
Ubicación: Chile!
Mensajes: 776
Antigüedad: 19 años, 8 meses
Puntos: 56
Respuesta: form con dos action

Lo pillé! O al menos creo que es eso:
Has puesto un exit en la parte que verifica el código de seguridad O_o:

Código PHP:
session_start();
if (
$_POST['action'] == "checkdata") {
    if (
$_SESSION['tmptxt'] == $_POST['tmptxt']) {
        echo 
"Bienvenido";
    } else {
        echo 
"Intentalo nuevamente";
    }
    exit;

Creo que si quieres que el script se detenga si hay error, debiera ir dentro del IF, no fuera de él, si no siempre se ejecutará.

Código PHP:
session_start();
if (
$_POST['action'] == "checkdata") {
    if (
$_SESSION['tmptxt'] == $_POST['tmptxt']) {
        echo 
"Bienvenido";
    } else {
        echo 
"Intentalo nuevamente"
        exit;
    }

¿Será eso? o_o
__________________
pipus.... vieeeeeji plomius!!!
*quinqui site*
  #6 (permalink)  
Antiguo 29/07/2008, 12:26
Avatar de leskolpykos  
Fecha de Ingreso: junio-2007
Ubicación: Caracas
Mensajes: 96
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: form con dos action

diosssssssss funcionaaaaaaaaaaaa graciaaaaaaaaasssssssssssssssssss

ya lo probé en localhost, voy a probarlo en el servidor a ver... era eso!!!!

aunque me queda una duda, ve al final del for que hay dos input.... pueden ir dos?
__________________
www.luisespectaculo.net el portal de artistas y farándula más grande de Venezuela!

Última edición por leskolpykos; 29/07/2008 a las 12:36
  #7 (permalink)  
Antiguo 29/07/2008, 15:01
Avatar de quinqui  
Fecha de Ingreso: agosto-2004
Ubicación: Chile!
Mensajes: 776
Antigüedad: 19 años, 8 meses
Puntos: 56
Respuesta: form con dos action

Cita:
Iniciado por leskolpykos Ver Mensaje
aunque me queda una duda, ve al final del for que hay dos input.... pueden ir dos?
Pues claro que sí xP
__________________
pipus.... vieeeeeji plomius!!!
*quinqui site*
  #8 (permalink)  
Antiguo 29/07/2008, 15:14
Avatar de leskolpykos  
Fecha de Ingreso: junio-2007
Ubicación: Caracas
Mensajes: 96
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: form con dos action

gracias quinqui..

aqui te dejo el link de mi libro de visitas para que veas ya el código captcha funcionando :D

gracias por la ayuda!!

http://www.luisespectaculo.net/libro/default.php
__________________
www.luisespectaculo.net el portal de artistas y farándula más grande de Venezuela!
  #9 (permalink)  
Antiguo 29/07/2008, 20:32
Avatar de quinqui  
Fecha de Ingreso: agosto-2004
Ubicación: Chile!
Mensajes: 776
Antigüedad: 19 años, 8 meses
Puntos: 56
Respuesta: form con dos action

Wiiii! No pude firmar xD
Al poner el mouse sobre el texto de Captcha, el foco se devuelve a la caja del Usuario xD!
__________________
pipus.... vieeeeeji plomius!!!
*quinqui site*
  #10 (permalink)  
Antiguo 29/07/2008, 23:05
Avatar de leskolpykos  
Fecha de Ingreso: junio-2007
Ubicación: Caracas
Mensajes: 96
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: form con dos action

habia un error en la cantidad de caracteres, y creo que ya esta solucionado.. si kieres intentalo a ver.. :D

http://www.luisespectaculo.net/libro/default.php
__________________
www.luisespectaculo.net el portal de artistas y farándula más grande de Venezuela!

Última edición por leskolpykos; 29/07/2008 a las 23:12
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:52.