Ir al contenido


Foto

Funcion valida formulario.


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 mensajes

Escrito 29 noviembre 2012 - 04:20

Hola, tengo esta función que valida un formulario y hace una serie de condiciones. El problema lo tengo en que necesito sacar la variable NUM_USUARIO:

[html5]
window.location.href = "menu3.php?id="+NUM_USUARIO;////Aquí es donde quiero sacar el valor del cod valida1.php///////
[/html5]

Con esta función llamo al php valida1.php y valido el formulario con la variable _TELEFONO:
[js]
function nuevoAjax() {

    var xmlhttp=false;

    try {

        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");

    }

        catch(e){

        try{

            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

        }catch(E) {

            if (!xmlhttp && typeof XMLHttpRequest!='undefined')

                xmlhttp=new XMLHttpRequest();

        }

    }

    return xmlhttp;

}



function TelefonoExiste(_TELEFONO, _callback) {
   
divResultado = document.getElementById('resultado');

    var ajax=nuevoAjax();

  ajax.open("GET", "valida1.php?TELEFONO=" + encodeURIComponent(_TELEFONO), true);
 
    ajax.onreadystatechange=function() {

        if ((ajax.readyState==4) && (ajax.status==200)){

            //ejecutamos _callback como si fuese una función, pasandole el parámetro

            _callback(ajax.responseText);

        }

    }

    ajax.send(null);

}


function GuardaFormulario() {

    //usemos mejor las CoLECCIONES, y variables, así ahorramos codigo y lo hace fácil de mantener

    var _TELEFONO = document.forms['form1'].elements['TELEFONO'];



    if (_TELEFONO.value.length == 0){

        alert("Insertar el Teléfono");

        _TELEFONO.focus();

        return 0;

    }

   

    //lamamos a AJAX:

TelefonoExiste(_TELEFONO.value, function(resp) {

if (parseInt(resp) == 1) {


var boton = confirm("¡Usuario existente!¿Desea hacer un nuevo registro?");


if (boton){


window.location.href = "menu3.php?id="+NUM_USUARIO;////Aquí es donde quiero sacar el valor del cod valida1.php///////

} else {

window.location.href = "menu4.php";

    }

}
if (parseInt(resp) == 0) {

  alert("¡El Cliente se ha dado de alta!");

  document.forms['form1'].submit();////Aquí mando el formulario si el teléfono no existe.
  }

});
return 0;
}

[/js]


valida1.php


<?php
  header("Cache-Control: no-store, no-cache, must-revalidate");
  require_once('Connections/conexion.php');
  $TELEFONO = isset($_GET['TELEFONO']) ? $_GET['TELEFONO']:"";
  $query=("SELECT TELEFONO,NUM_USUARIO FROM usuarios WHERE TELEFONO ='".$TELEFONO."'");
  $result = mysql_query($query);
  $rows = mysql_num_rows($result);
  if ($rows>=0) {
  echo '1';
  }else{
echo '0'; 
  }
?>


GRACIAS
  • 0




IP.Board spam blocked by CleanTalk.