Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/12/2015, 17:12
escorpion_vg
 
Fecha de Ingreso: diciembre-2015
Mensajes: 1
Antigüedad: 8 años, 4 meses
Puntos: 0
Pregunta No enviar formulario si da error

Hola buenas.
Estoy haciendo un formulario y quiero que cuando un usuario ponga un dirección de email invalida el formulario no se envié a la base de datos.
Código PHP:
<!DOCTYPE html>
<html lang="es">
    <head>
    
        <title>Control de Acceso a Usuarios por Perfiles</title>


    </head>
    
    <body>
<div style="border: 5px double;">    
    <form name="login" action="execute.php" method="post">
        <label>Login Name:</label><br />
        <input type="text" name="usern" maxlength="10" /><br />
        <label>Password:</label><br />
        <input type="password" name="pass" maxlength="10" /><br />
        <input type="submit" name="SEND" value="SEND" />
    </form>
 </div><br/>
<div style="border: 5px solid;">    
<!-- formulario registro -->
<?php
// define variables and set to empty values
$emailErr "";
$mail "";

if (
$_SERVER["REQUEST_METHOD"] == "POST") {

  
   if (empty(
$_POST["mail"])) {
     
$mailErr "Email is required";
   } else {
     
$mail test_input($_POST["mail"]);
     
// check if e-mail address is well-formed
     
if (!filter_var($mailFILTER_VALIDATE_EMAIL)) {
       
$emailErr "Invalid email format";
     }
   }
}

function 
test_input($data) {
   
$data trim($data);
   
$data stripslashes($data);
   
$data htmlspecialchars($data);
   return 
$data;
}
?>

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" >
  <fieldset>
    <legend  style="font-size: 18pt"><b>Registro</b></legend>
    <div class="form-group">
      <label><b>Ingresa tu login</b></label>
      <input type="text" name="loginName" class="form-control" placeholder="Ingresa tu login" />
    </div>
    <div class="form-group">
      <label><b>Ingresa tu Password</b></label>
      <input type="password" name="passuser" class="form-control"  placeholder="Ingresa contraseña" />
    </div>
    <div class="form-group">
      <label style="font-size: 14pt"><b>Repite tu contraseña</b></label>
      <input type="password" name="rpassuser" class="form-control" required placeholder="repite contraseña" />
    </div>
       <div class="form-group">
      <label><b>Ingresa tu mail</b></label>
      <input type="text" name="mail" class="form-control" placeholder="Ingresa tu mail" />
         <span class="error">* <?php echo $emailErr;?></span>
    </div>
    </div>
   
    <input  class="btn btn-danger" type="submit" name="submit" value="Registrarse"/>

  </fieldset>
</form>
</div>
<?php

        
if(isset($_POST['submit'])){
            require(
"registro.php");
        }
    
?>
<!--Fin formulario registro -->

        </td>
        </tr>
        </table>
        </div></center></div></center>

    
</body>
</html>
 </div>
 
    </body>
</html>