PHP Classes

Exception for data validation: Validate and throw exceptions for invalid values

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 160 All time: 8,971 This week: 455Up
Version License PHP version Categories
exception-validation 1.0GNU General Publi...5PHP 5, Validation
Description 

Author

This is a very simple package can validate and throw exceptions for invalid values.

It can validate user accounts with a email and password.

The classes throw exceptions if invalid user details are provided.

Picture of FERNANDO CUNHA
  Performance   Level  

 

Example

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.

@author FERNANDO CUNHA
-->
<?php

   
require 'LoginDAO.php';
    require
'LoginController.php';
?>


<html>
    <head>
        <meta charset="UTF-8">
        <title>Use exception for data validation</title>
    </head>
    <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
    <body>
        <?php
       
        
if( !isset($_POST['submit']) ):
       
?>
<form action="index.php" method="post">
            <h1>Login de acesso</h1>
             <div class="form-group">
                 <input id="loginEmail" name="email" type="text" class="form-control" placeholder="Email" tabindex="1" style="width:40%">
                </div>
                <div class="form-group">
                    <input id="pwd" name="pwd" type="password" class="form-control" placeholder="password" tabindex="2" style="width:40%">
                 </div>
                <div class="form-group">
                    <input class="btn btn-primary" name="submit" type="submit" value="Login" tabindex="3"/>
                </div>
        </form>
       
        <?php
       
else:
          
           
$email = $_POST['email'];
           
$pwd = $_POST['pwd'];
           
            try{
                
$controller = new LoginController();
                
$controller->isValidLogin($email, $pwd);
           
            }catch (
PDOException $ex1) {
                print
$ex1->getMessage();
            }
             catch (
Exception $ex2) {
                print
$ex2->getMessage();
            }
           
           
        endif;
       
?>
</body>
</html>


Screenshots (1)  
  • print.jpg
  Files folder image Files (22)  
File Role Description
Files folder imageDirectoryIterator (2 files, 1 directory)
Files folder imageExceptionsValidationData (4 files)
Files folder imageFTP (2 files, 1 directory)
Files folder imageMVC (3 files)
Files folder imagenbproject (2 files)
Files folder imageSingleton (2 files)

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 95%
Total:160
This week:0
All time:8,971
This week:455Up