Autor Tema: Como pasar un dato de PHP a HTML validación sobre el propio formulario  (Leído 4766 veces)

Maxzama

  • Sin experiencia
  • *
  • APR2.COM
  • Mensajes: 7
    • Ver Perfil
Hola a todos el cual pertenecen a este Grupo de programadores, jajaj.

La situación es la siguiente, tengo dos documentos (.php), uno es la pantalla principal el cual uso html y El otro es de validación.

El caso es que los mensaje dado a los campo en la pantalla de validación no se expresa o se muestra en la pantalla html.

Se que en la pantalla principal el cual contiene html nos ayuda el <Form con POST y la dirección al enviar los datos a procesar.

Pero en el caso de la pantalla validación, el cual recibe los datos de  la pantalla principal. El deberia validar estos campo si estan vacio o no lo estan, y si es numerico o no. Despues mandar un mensaje el cual se mostrara en la pantalla Principal(Que en este caso no me lo muestra).

en este caso utilizo $_SESSION, el cual me ayuda que se vea en la otra pantalla( es decir el va a la pantalla de validación al presionar guardar y regresar a la pantalla principal el muestra su mensaje). Pero si resfresca la pantalla principal o te vas a menú auxiliar y regresas a la pantalla principal sigue mostrando el valor que tiene   $_SESSION el cual fue expresado en la pantalla validación.

Código de validación:
 
Código: [Seleccionar]
<?

 session_start();
  $id_usuario = $_SESSION['id_usuario'];
  require '..\include\conectar.php';
 

$Seleccion = $_POST['Seleccion_Ingresar'];
 
//validación del formulario  9         
if($Seleccion==" ") {   
               
                         $riff = $_POST['rif']; //extraemos la variable         


                     if ($riff == "" ){
                                          $msgrif = "Falta Ingresar la Rif";
                                                          $_SESSION['msgrif'] = $msgrif;
                                         //$HTTP_POST_VARS['msgrif'] = $msgrif;
 
                                               //$claserif = "error";
header("location:actualizar_datoss_.php");
                                      } else {
                                        if (!is_numeric($riff)) {
                                                  $msgrif = "Rif debe ser numerica";
  $_SESSION['msgrif'] = $msgrif;
                                                //$claserif = "error";
  header("location:actualizar_datoss_.php");
                                          }
                                      }
         

               }else{
               if($Seleccion=="1") {
                                   }else{

 
                     header("location:panel_menu.php");
  }
 }
?>

Código de pantalla principal (como lo llamo):
este código lo coloco antes del código html.

Código: [Seleccionar]
<?
  session_start();
  $id_usuario = $_SESSION['id_usuario'];
  //$msgrif = $HTTP_POST_VARS['msgrif'];
 
  if (isset($_SESSION['msgrif'])){                     // Aqui es donde llamo o obtengo de la pantalla validacion
$msgrif = $_SESSION['msgrif'];
}else{
header('location:act_docentes_.php');
}
 
 
  require '..\include\conectar.php';
  $reg = mysql_db_query($dat,"select * from docentes where ceduladoce='$id_usuario'");
  if(mysql_num_rows($reg)=='0')
    header("location:ingreso.php");
  $row = mysql_fetch_array($reg);
  if($row[correodoce]==NULL)
    $crr = 0;
  else
    $crr = 1;
  $reg1 = mysql_db_query($dat,"select * from municipios where codigoesta='07'");
  $reg4 = mysql_db_query($dat,"select * from listado_posgrado");
  $reg5 = mysql_db_query($dat,"select * from listado_pregrado");
?>


Espero sus respuesta por favor y gracias...
« Última modificación: 27 de Febrero 2016, 11:04 por César Krall »

César Krall

  • Moderador Global
  • Experto
  • *******
  • Mensajes: 2078
  • No vales por lo que dices, sino por lo que haces
    • Ver Perfil
    • aprenderaprogramar.com
Re:Como pasar un dato de php a htlm
« Respuesta #1 en: 27 de Febrero 2016, 11:03 »
Hola! Para analizar lo que ocurre sería necesario todo el código, incluido el HTML.

Es probable que no tengas algo bien planteado.

El proceso normal sería:

1. Tenemos un formulario donde el usuario introduce los datos y que envía a una url llamémosla validacion.php

2. En validacion.php se comprueba si los datos son correctos y según lo sean o no se hace una cosa u otra

Si lo que quieres es mostrar los resultados de validación sobre la propia pantalla inicial del formulario (lo cual es complicarse un tanto) necesitarías enviar a la propia pantalla del formulario información indicando si se trata de una validación o de una entrada de datos. Esta información podría ser un envío con post del valor de una variable (o con una variable de sesión)

Una alternativa interesante puede ser usar Ajax para validar en la propia pantalla del formulario pero sin necesidad de enviar a otra pantalla, sino hacerlo en segundo plano impidiendo que el formulario se envíe si no cumple la validación. Para esto necesitas Ajax, se explica en el curso http://aprenderaprogramar.com/index.php?option=com_content&view=category&id=83&Itemid=212

Saludos!
Responsable de departamento de producción aprenderaprogramar.com

Maxzama

  • Sin experiencia
  • *
  • APR2.COM
  • Mensajes: 7
    • Ver Perfil
Re:Como pasar un dato de PHP a HTML validación sobre el propio formulario
« Respuesta #2 en: 29 de Febrero 2016, 15:37 »
Hey Hola Cesar.

Este es el código de Html:

Código: [Seleccionar]
<?
  session_start();
  $id_usuario = $_SESSION['id_usuario'];
 

  include 'act_docentes_.php';   // Pantalla de valdación
  //$rif = $msgrif;
  $msgrif = $_POST['msgrif']
 
 
  require '..\include\conectar.php';
  $reg = mysql_db_query($dat,"select * from docente where ceduladoce='$id_usuario'");
  if(mysql_num_rows($reg)=='0')
    header("location:ingreso.php");
  $row = mysql_fetch_array($reg);
  if($row[correodoce]==NULL)
    $crr = 0;
  else
    $crr = 1;
  $reg1 = mysql_db_query($dat,"select * from municipios where codigoesta='07'");
  $reg4 = mysql_db_query($dat,"select * from listado_posgrado");
  $reg5 = mysql_db_query($dat,"select * from listado_pregrado");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ingreso al Sistema</title>
<link href="../estilos/recibos.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.Estilo2 {font-size: 12; font-weight: bold; }
-->

div {
margin: 5px;
}

input {
padding: 5px;
border: solid 1px Gray; /* color de linea */
}

.msg {
color: red; /*color fuente mensaje error */
font-size: 13px;
}


</style>
<script language="JavaScript" type="text/javascript">
function enfoque() {
  document.form1.fecha.focus();
}
function salir() {
  document.location.href="panel_menu.php";
}
</script>
<script language="JavaScript" type="text/javascript">
function parroquias(mun)
{
  var cod = mun;
  var x = document.form1.parroquia.length;
  for(var i = 0; i < x; i++)
    document.form1.parroquia.remove(document.form1.parroquia.options[i]);
  document.form1.parroquia[0] = new Option("Seleccione Parroquia", 'null');
  <?
    $reg2 = mysql_db_query($dat,"select * from municipios where codigoesta='07'");
    while($row2 = mysql_fetch_array($reg2)) {
  ?>
      if(cod == '<? echo $row2[codigomuni];?>') {
    <?
    $reg3 = mysql_db_query($dat,"select * from parroquias where codigomuni=".$row2[codigomuni]." order by descriparr");
        while($row3 = mysql_fetch_array($reg3)) {
?>
      document.form1.parroquia[document.form1.parroquia.length] = new Option("<? echo $row3[descriparr];?>", '<? echo $row3[codigoparr];?>');
    <?
        }
    ?>
  }
  <?
    }
  ?>
}

</script>
</head>

<body onload="enfoque();" class="body">
<table width="950" border="1" cellspacing="0" bordercolor="#3399CC">
  <tr>
    <td>
<table width="1046" border="0" class="pantalla">
  <tr>
    <td width="18">&nbsp;</td>
          <td width="890"><img src="../images/logoC.jpg" width="751" height="57" /></td>
    <td width="20">&nbsp;</td>
  </tr>
  <tr>
    <td height="270">&nbsp;</td>      <td align="center">
<form id="form1" name="form1" method="post" action="act_docentes_.php"  onsubmit="" enctype="a pplication/x-www-form-urlencoded">
              <table width="815" border="0" cellspacing="0" class="marcoforma">
                <tr class="topemarco">
                     <td width="20" height="34" bgcolor="#FF0000">&nbsp;</td> 
                     <td colspan="2" bgcolor="#FF0000">
                     <div align="center">Actualizaci&oacute;n de Datos</div></td>
                     <td width="22" bgcolor="#FF0000">&nbsp;</td>
                </tr>
                <tr>
                    <td width="20">&nbsp;</td>
                    <td width="126" class="textolabel">C&eacute;dula:</td>
                        <td  width="635" align="left"> <input name="cedula" type="text" class="textollena" id="cedula" value="V<? echo $row[ceduladoce];?>" size="10" maxlength="10" readonly="true" OnFocus="toma_seleccion(this)" OnChange="pon_seleccion(this)" /></td>
                    <td>&nbsp;</td>
                </tr>
<tr>
                  <td width="20">&nbsp;</td>
                            <td width="126" class="textolabel">Rif:</td>
                                 
<td  width="635" align="left">
                                          <input name="rif" type="text" class="textollena" id="rif" value="<? echo $row[rifdoce];?>" size="12" maxlength="9" onKeyUp="" />
                                          <font color="#FF0000">*</font>
                      <font  SIZE=2 color="#FF0000">Ejemplo: Colocar 218687747 ; </font>
                                       
  <span class="msg"><?php echo $msgrif?></span>   <!--  Donde Se Mostrara el Mensaje Validado -->
                  </td>
         
                  <td>&nbsp;</td>
                </tr>
<tr>
                  <td width="20">&nbsp;</td>
                      <td class="textolabel">Titulo T.S.U:</td>
  <td align="left"> <input name="titulotsu" type="text" class="textollena" id="titulotsu" value="<? echo $row[titulotsudoce];?>" size="80" maxlength="9" onKeyUp="chequea_3()" />
                    <font color="#FF0000">*</font> </td>
                  <td>&nbsp;</td>
                </tr>
<tr>
                  <td width="20">&nbsp;</td>
                      <td class="textolabel">Titulo Postgrado:</td>
  <td align="left"> <input name="titulopos" type="text" class="textollena" id="titulopos" value="<? echo $row[tituloposdoce];?>" size="80" maxlength="9" onKeyUp="chequea_3()" />
                    <font color="#FF0000">*</font> </td>
                  <td>&nbsp;</td>
                </tr>
<tr>
                  <td width="20">&nbsp;</td>
                      <td class="textolabel">Titulo Pregrado:</td>
                      <td align="left"> <select name="titulopre" class="textollena" id="titulopre" readonly="true" style="font-size:7pt">
                          <option value="" selected>Seleccione el titulo Pregrado</option>
                                              <? while($row3 = mysql_fetch_array($reg5)) {?>
                                              <? if($row[codigopre]==$row3[codigopre]) {?>
                                              <option value="<? echo $row3[descripre];?>"><? echo $row3[descripre];?></option>
                                              <? } else {?>
                                              <option value="<? echo $row3[descripre];?>"><? echo $row3[descripre];?></option>
                                              <? }?>
                                              <? }?>
                                        </select>
                    <font color="#FF0000">*</font> </td>
                  <td>&nbsp;</td>
                </tr>

                <tr>
                  <td width="20">&nbsp;</td>
                        <td class="textolabel">Nombres:</td>
                        <td align="left"> <input name="nombre" type="text" class="textollena" id="nombre" value="<? echo $row[nombredoce];?>" size="25" maxlength="25" readonly="true"  OnFocus="toma_seleccion(this)" OnChange="pon_seleccion(this)" />
                  </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>
                       <td class="textolabel">Apellidos:</td>
                       <td align="left"> <input name="apellido" type="text" class="textollena" id="apellido" value="<? echo $row[apellidodoce];?>" size="25" maxlength="25" readonly="true"  />
                  </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>
                       <td class="textolabel">Fecha de Nacimiento:</td>
                       <td align="left"> <input name="fecha" type="text" class="textollena" id="fecha" value="<? echo substr($row[fechanaci],8,2).'/'.substr($row[fechanaci],5,2).'/'.substr($row[fechanaci],0,4);?>" size="10" maxlength="10"   OnFocus="toma_seleccion(this)" OnChange="pon_seleccion(this)" />
                       <font color="#FF0000">*</font> </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>
                      <td class="textolabel">Sexo:</td>
                      <td align="left"> <select name="sexo" class="textollena" id="sexo">
                           <? if($row[sexodoce]=='F') {?>
                           <option value="F" selected>Femenino</option>
                           <? } else {?>
                           <option value="F">Femenino</option>
                           <? }?>
                           <? if($row[sexodoce]=='M') {?>
                           <option value="M" selected>Masculino</option>
                           <? } else {?>
                           <option value="M">Masculino</option>
                           <? }?>
                           </select>
                           <font color="#FF0000">*</font> </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>
                      <td class="textolabel">Telefono:</td>
                      <td align="left"> <input name="telefono" type="text" class="textollena" id="telefono2" value="<? echo $row[telefodoce];?>" size="30" maxlength="39" />
                      <font color="#FF0000">*</font> </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>
                      <td class="textolabel">Correo Electr&oacute;nico:</td>
                      <td align="left"> <input name="correo" type="text" class="textollena" id="correo" value="<? echo $row[correodoce];?>" size="40" maxlength="50" />
                      <font color="#FF0000">*</font>
                      <input name="cuenta" type="hidden" id="cuenta" value="<? echo $crr;?>" />
                  </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>
                      <td class="textolabel">Municipio:</td>
                      <td align="left"> <select name="municipio" class="textollena" id="municipio" onchange="parroquias(this.value);"  readonly="true" >
                          <option value=" " selected>Seleccione Municipio</option>
                          <? while($row1 = mysql_fetch_array($reg1)) {?>
                          <? if($row[codigomuni]==$row1[codigomuni]) {?>
                          <option value="<? echo $row1[codigomuni];?>" selected><? echo $row1[descrimuni];?></option>
                          <? } else {?>
                          <option value="<? echo $row1[codigomuni];?>"><? echo $row1[descrimuni];?></option>
                          <? }?>
                          <? }?>
                          </select>
                          <font color="#FF0000">*</font> </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>
                  <td class="textolabel">Parroquia:</td>
                  <td align="left"> <select name="parroquia" class="textollena" id="parroquia" >
                      <option value=" ">Seleccione Parroquia</option>
                    </select>
                    <font color="#FF0000">*</font> </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>
                  <td class="textolabel">Direcci&oacute;n:</td>
                  <td rowspan="2" align="left" valign="top"> <textarea name="direccion" cols="45" rows="3" class="textollena" id="direccion"><? echo $row[direcciondoce];?></textarea>
                  </td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>
                  <td width="126">&nbsp;</td>
                  <td width="22">&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>
                  <td colspan="2" align="center"> <table width="450" border="0" cellspacing="0">
                      <tr>
                        <td width="100" align="center"><input type="submit" name="Submit" value="Guardar"  /></td>
                        <td width="100" align="center"><input type="reset" name="Submit2" value="Reiniciar" disabled=true /></td>
                        <td width="100" align="center"><input type="button" name="Submit3" value="Salir"  disabled=true / onclick="salir();"></td>
                      </tr>
                    </table></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="20">&nbsp;</td>           
                  <td colspan="2"><font color="#FF0000" SIZE=2>Campo Obligatorio a llenar: ( * )</font> </td>
 
                  <td>&nbsp;</td>
                </tr>
<tr>
     <td width="20">&nbsp;</td>
                      <td  colspan="2" align="left">     
  <font color="#FF0000" SIZE=2>Datos a Ingresar:</font>   
  <select name="Seleccion_Ingresar" class="textollena" id="Seleccion_Ingresar" readonly="true" style="font-size:8pt">
                          <option value=" " selected>Seleccione los Datos a Ingresar</option>
  <option value="1">Rif</option>
  <option value="2">Rif hasta Titulo T.S.U</option>
  <option value="3">Rif hasta Titulo Postgrado</option>
                                              <option value="4">Rif hasta Titulo Pregrado</option>
                                        </select>
<font color="#FF0000" SIZE=2>Esta función, es sino obtiene todos los datos pedidos</font>
                  <td>&nbsp;</td>
</tr>
              </table>
            </form>
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td height="100">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
    </td>
  </tr>
</table>
</body>
</html>



Maxzama

  • Sin experiencia
  • *
  • APR2.COM
  • Mensajes: 7
    • Ver Perfil
Re:Como pasar un dato de PHP a HTML validación sobre el propio formulario
« Respuesta #3 en: 29 de Febrero 2016, 15:38 »
Y ahora el código que utilizo en Validación:
Código: [Seleccionar]
<?

 session_start();
  $id_usuario = $_SESSION['id_usuario'];
  require '..\include\conecta.php';

$Seleccion = $_POST['Seleccion_Ingresar'];
 //validación del formulario  9       
if($Seleccion==" ") {   
       
                         //var_dump($_POST);         
                         $riff = $_POST['rif']; //extraemos la variable         
 

                     if ($riff == "" ){
                                          $msgrif = "Falta Ingresar la Rif";
  $_POST['msgrif'] = $msgrif;
  header("location:actualizar_datoss_.php");
                                      } else {
                                            if (!is_numeric($riff)) {
                                                                      $msgrif = "Rif debe ser numerica";
                              $_POST['msgrif'] = $msgrif;
                                                                      //$claserif = "error";
                              header("location:actualizar_datoss_.php");
                                                                      }
                                             }
                        /*if ($clasetitulo == "" && $claserif == "" ) {
                                                                  //agregar el elemento o la accion deseada
                                                                echo "OK"; // Ej. Guardado correctamente
                                                                  } */
         

                     }elseif($Seleccion=="1") {
                        $riff = $_POST['rif']; //extraemos la variable

                        if ($riff == "" ){
                                                                $msgrif = "Falta Ingresar la Rif";
                        //$HTTP_POST_VARS['msgrif'] = $msgrif;
                        $_POST['msgrif'] = $msgrif;
                                                                  //$claserif = "error";
                        header("location:actualizar_datoss_.php");
                                                                  } else {
                                                                        if (!is_numeric($riff)) {
                                                                                                   $msgrif = "Rif debe ser numerica";
                                                           $_POST['msgrif'] = $msgrif;
                                                                                                   //$claserif = "error";
                                                           header("location:actualizar_datoss_.php");
                                                                                                  }
                                                                         }

                                                }elseif($Seleccion=="2") {
                         $riff = $_POST['rif']; //extraemos la variable
$tsu = $_POST['titulotsu']; //extraemos la variable

                                                     if ($riff == "" ){
                                                                                             $msgrif = "Falta Ingresar la Rif";
                                                     //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                     $_POST['msgrif'] = $msgrif;
                                                                                               //$claserif = "error";
                                                     header("location:actualizar_datoss_.php");
                                                                                              }else {
                                                                                                  if (!is_numeric($riff)) {
                                                                                                                             $msgrif = "Rif debe ser numerica";
                                                                                     $_POST['msgrif'] = $msgrif;
                                                                                                                             //$claserif = "error";
                                                                                     header("location:actualizar_datoss_.php");
                                                                                                                            }
}
 
  if ($tsu == "" ){
                                                                                             $msgtsu = "Falta Ingresar la Titulo_T.S.U";
                                                     //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                     $_POST['msgtsu'] = $msgtsu;
                                                                                               //$claserif = "error";
                                                     header("location:actualizar_datoss_.php");
                                                                                              }

                                                                            }elseif($Seleccion=="3") {
                        $riff = $_POST['rif']; //extraemos la variable
                            $tsu = $_POST['titulotsu']; //extraemos la variable
$pos = $_POST['titulopos']; //extraemos la variable

                                                                                if ($riff == "" ){
                                                                                                                        $msgrif = "Falta Ingresar la Rif";
                                                                                //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                                                $_POST['msgrif'] = $msgrif;
                                                                                                                          //$claserif = "error";
                                                                                header("location:actualizar_datoss_.php");
                                                                                                                         }else {
                                                                                                                              if (!is_numeric($riff)) {
                                                                                                                                                         $msgrif = "Rif debe ser numerica";
                                                                                                                 $_POST['msgrif'] = $msgrif;
                                                                                                                                                         //$claserif = "error";
                                                                                                                 header("location:actualizar_datoss_.php");
                                                                                                                                                         }
}    
 
                            if ($tsu == "" ){
                                                                                                                        $msgtsu = "Falta Ingresar la Titulo_T.S.U";
                                                                                //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                                                $_POST['msgtsu'] = $msgtsu;
                                                                                                                          //$claserif = "error";
                                                                                header("location:actualizar_datoss_.php");
                                                                                                                        }

                        if ($pos == "" ){
                                                                                                                        $msgpos = "Falta Ingresar la Titulo_Postgrado";
                                                                                //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                                                $_POST['msgpos'] = $msgpos;
                                                                                                                          //$claserif = "error";
                                                                                header("location:actualizar_datoss_.php");
                                                                                                                        }
                                                                                                        }elseif($Seleccion=="4") {
                         $riff = $_POST['rif']; //extraemos la variable
                                                         $tsu = $_POST['titulotsu']; //extraemos la variable
                             $pos = $_POST['titulopos']; //extraemos la variable
$pre = $_POST['titulopre']; //extraemos la variable

                                                                                                             if ($riff == "" ){
                                                                                                                                                     $msgrif = "Falta Ingresar la Rif";
                                                                                                             //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                                                                             $_POST['msgrif'] = $msgrif;
                                                                                                                                                       //$claserif = "error";
                                                                                                             header("location:actualizar_datoss_.php");
                                                                                                                                                      }else {
                                                                                                                                                            if (!is_numeric($riff)) {
                                                                                                                                                                                        $msgrif = "Rif debe ser numerica";
                                                                                                                                                $_POST['msgrif'] = $msgrif;
                                                                                                                                                                                        //$claserif = "error";
                                                                                                                                                header("location:actualizar_datoss_.php");
                                                                                                                                                                                       }
}
 
                                                          if ($tsu == "" ){
                                                                                                                                                     $msgtsu = "Falta Ingresar la Titulo_T.S.U";
                                                                                                             //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                                                                             $_POST['msgtsu'] = $msgtsu;
                                                                                                                                                       //$claserif = "error";
                                                                                                             header("location:actualizar_datoss_.php");
                                                                     
                                                                                                                                                          }

                                                      if ($pos == "" ){
                                                                                                                                                     $msgpos = "Falta Ingresar la Titulo_Postgrado";
                                                                                                             //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                                                                             $_POST['msgpos'] = $msgpos;
                                                                                                                                                       //$claserif = "error";
                                                                                                                                                             header("location:actualizar_datoss_.php");
//die;
                                                                                                                                                      }
  if ($pre == "" ){
                                                                                                                                                     $msgpre = "Falta Ingresar la Titulo_Pregrado";
                                                                                                             //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                                                                             $_POST['msgpre'] = $msgpre;
                                                                                                                                                       //$claserif = "error";
                                                                                                             header("location:actualizar_datoss_.php");
                                                                                                                                                      }
                                                                                                                                     }else{
        $reg = mysql_db_query($dat,"select * from docentes where ceduladoce='$id_usuario'");
                             if(mysql_num_rows($reg)=='0')
                                     header("location:ingreso.php");
                                     $rif = $_POST['rif'];
                                     $titulotsu = $_POST['titulotsu'];
                                     $titulopre = $_POST['titulopre'];
                                     $titulopos = $_POST['titulopos'];
                                     $fecha = $_POST['fecha'];
                                     $sexo = $_POST['sexo'];
                                     $telefono = $_POST['telefono'];
                                     $correo = $_POST['correo'];
                                     $municipio = $_POST['municipio'];
                                     $parroquia = $_POST['parroquia'];
                                     $direccion = $_POST['direccion'];
                                     $fec = substr($fecha,6,4).'-'.substr($fecha,3,2).'-'.substr($fecha,0,2);
                                     mysql_db_query($dat,"update docentes set  rifdoce='$rif', titulotsudoce='$titulotsu', titulopredoce='$titulopre', tituloposdoce='$titulopos', fechanaci='$fec', sexodoce='$sexo', telefodoce='$telefono', correodoce='$correo', codigomuni='$municipio', codigoparr='$parroquia', direcciondoce='$direccion' where ceduladoce='$id_usuario'");

                                     header("location:panel_menu.php");
   
                                                                                                                                          }               
                                                                                     
?>

el Mensaje el cual debería salir, después de ser validado algún campo que debería introducir el docente. Es llamado con el siguiente codigo dentro de un span:
Código: [Seleccionar]
<span class="msg"><?php echo $msgrif?></span>
Espero tu respuesta por favor y gracias...

Maxzama

  • Sin experiencia
  • *
  • APR2.COM
  • Mensajes: 7
    • Ver Perfil
Re:Como pasar un dato de PHP a HTML validación sobre el propio formulario
« Respuesta #4 en: 29 de Febrero 2016, 20:08 »
Resuelto el problema:

Código de validación:
Código: [Seleccionar]
<?
session_start();
$Seleccion = $_POST['Seleccion_Ingresar'];
$errores = array();
 //validación del formulario  9       
if($Seleccion==" ") {   
       
                         //var_dump($_POST);         
                         $riff = $HTTP_POST_VARS['rif']; //extraemos la variable         
                         //$titulo = $_POST["titulo"];
   
                         //var dump($riff); //valida si campo rif existe
                        //var dump($titulo); //valida si campo edad existe
   
                        // Si los datos existen o no para campo (nombre/edad)
                    //$claserif = ""; //Muestra el error color "naranja"
                    //$clasetitulo = ""; //Muestra el error color "naranja"

                    //if ($titulo == ""){
                                            //$msgtitulo = "Falta Ingresar el Titulo";
                                          //$clasetitulo = "error";
                                     // }

                     if ($riff == "" ){
                                          $msgrif = "Falta Ingresar la Rif";
  $_SESSION['msgrif'] = $msgrif;
                                            //$claserif = "error";
  $errores[]=true;
  header("location:actualizar_datoss_.php");
                                      } else {
                                            if (!is_numeric($riff)) {
                                                                      $msgrif = "Rif debe ser numerica";
                              $_SESSION['msgrif'] = $msgrif;
                                                                      //$claserif = "error";
  $errores[]=true;
                              header("location:actualizar_datoss_.php");
                                                                      }
                                             }
                        /*if ($clasetitulo == "" && $claserif == "" ) {
                                                                  //agregar el elemento o la accion deseada
                                                                echo "OK"; // Ej. Guardado correctamente
                                                                  } */
         

                     }elseif($Seleccion=="1") {
                         $riff = $HTTP_POST_VARS['rif']; //extraemos la variable
$tsu = $HTTP_POST_VARS['titulotsu']; //extraemos la variable

                                                     if ($riff == "" ){
                                                                                             $msgrif = "Falta Ingresar la Rif";
                                                     //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                     $_SESSION['msgrif'] = $msgrif;
                                                                                               //$claserif = "error";
$errores[]=true;
                                                     header("location:actualizar_datoss_.php");
                                                                                              }else {
                                                                                                  if (!is_numeric($riff)) {
                                                                                                                             $msgrif = "Rif debe ser numerica";
                                                                                     $_SESSION['msgrif'] = $msgrif;
                                                                                                                             //$claserif = "error";
$errores[]=true;
                                                                                     header("location:actualizar_datoss_.php");
                                                                                                                            }
}
 
  if ($tsu == "" ){
                                                                                             $msgtsu = "Falta Ingresar la Titulo_T.S.U";
                                                     //$HTTP_POST_VARS['msgrif'] = $msgrif;
                                                     $_SESSION['msgtsu'] = $msgtsu;
                                                                                               //$claserif = "error";
$errores[]=true;
                                                     header("location:actualizar_datoss_.php");
                                                                                              }

                                                                            }
if (count($errores)>0)
{
     header("location:actualizar_datoss_.php");
 
}else{
       $id_usuario = $_SESSION['id_usuario'];
       $id_usuario = $_SESSION['id_usuario'];
       require '..\include\conectar.php';
       $reg = mysql_db_query($dat,"select * from docentes where ceduladoce='$id_usuario'");
       if(mysql_num_rows($reg)=='0')
           header("location:ingreso.php");
       $rif = $_POST['rif'];
       $titulotsu = $_POST['titulotsu'];
       $titulopre = $_POST['titulopre'];
       $titulopos = $_POST['titulopos'];
       $fecha = $_POST['fecha'];
       $sexo = $_POST['sexo'];
       $telefono = $_POST['telefono'];
       $correo = $_POST['correo'];
       $municipio = $_POST['municipio'];
       $parroquia = $_POST['parroquia'];
       $direccion = $_POST['direccion'];
       $fec = substr($fecha,6,4).'-'.substr($fecha,3,2).'-'.substr($fecha,0,2);
       mysql_db_query($dat,"update docentes set  rifdoce='$rif', titulotsudoce='$titulotsu', titulopredoce='$titulopre', tituloposdoce='$titulopos', fechanaci='$fec', sexodoce='$sexo', telefodoce='$telefono', correodoce='$correo', codigomuni='$municipio', codigoparr='$parroquia', direcciondoce='$direccion' where ceduladoce='$id_usuario'");
       header("location:pane_menu.php");
     }              
                                                                                     
?>

Maxzama

  • Sin experiencia
  • *
  • APR2.COM
  • Mensajes: 7
    • Ver Perfil
Re:Como pasar un dato de PHP a HTML validación sobre el propio formulario
« Respuesta #5 en: 29 de Febrero 2016, 20:15 »
Codigo de Html:

Código: [Seleccionar]
<?
  session_start();
  $id_usuario = $_SESSION['id_usuario'];
 
  if (isset($_SESSION['msgrif'])){
                                     $msgrif = $_SESSION['msgrif'];
                             }else{
                                 $msgrif = "";
                                      }
  unset($_SESSION['msgrif']);

  require '..\include\conect.php';
  $reg = mysql_db_query($dat,"select * from docentes where ceduladoce='$id_usuario'");
  if(mysql_num_rows($reg)=='0')
    header("location:ingres.php");
  $row = mysql_fetch_array($reg);
  if($row[correodoce]==NULL)
    $crr = 0;
  else
    $crr = 1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Donde se mostrara el mensaje- esto se coloca debajo de input:
Código:
Código: [Seleccionar]
<span class="msg"><?php echo $msgrif?></span>

César Krall

  • Moderador Global
  • Experto
  • *******
  • Mensajes: 2078
  • No vales por lo que dices, sino por lo que haces
    • Ver Perfil
    • aprenderaprogramar.com
Hola! Veo que lo has resuelto, gracias por poner la solución

Saludos!
Responsable de departamento de producción aprenderaprogramar.com

 

Sobre la educación, sólo puedo decir que es el tema más importante en el que nosotros, como pueblo, debemos involucrarnos.

Abraham Lincoln (1808-1865) Presidente estadounidense.

aprenderaprogramar.com: Desde 2006 comprometidos con la didáctica y divulgación de la programación

Preguntas y respuestas

¿Cómo establecer o cambiar la imagen asociada (avatar) de usuario?
  1. Inicia sesión con tu nombre de usuario y contraseña.
  2. Pulsa en perfil --> perfil del foro
  3. Elige la imagen personalizada que quieras usar. Puedes escogerla de una galería de imágenes o subirla desde tu ordenador.
  4. En la parte final de la página pulsa el botón "cambiar perfil".