PHP Classes

File: example

Recommend this page to a friend!
  Classes of Lukas Mestan   Get form value & error   example   Download  
File: example
Role: Example script
Content type: text/plain
Description: example of use form_class to get form value&errors
Class: Get form value & error
Keep track of form validation errors
Author: By
Last change:
Date: 14 years ago
Size: 979 bytes
 

Contents

Class file image Download
<?php

define
("USER_PW", "987654321");
session_start();
$form=new Form;

echo
'<form method="post" action=""><table>
        <tr class="head">
        <td>Heslo</td><td><input type="password" name="pass" value="'
.$form->value("pass").'"> '.$form->error("pass").'</td>
        </tr>
        <tr>
        <td colspan="2" align="center"><input type="submit" name="submit" value="Login"></td>
        </tr></table></form>'
;


if(isset(
$_POST["submit"])){
 
$pass=trim(htmlspecialchars($_POST["pass"]));
  if(
$pass==""){
   
$form->setError("pass", "* Password is empty");
  }
  if(
$pass!=USER_PW){
   
$form->setError("pass", "* Password is not set");
  }
  if(
$form->num_errors > 0){
       
$_SESSION['value_array'] = $_POST;
       
$_SESSION['error_array'] = $form->getErrorArray();
    }else{
      
$_SESSION['set_admin'] = true;
      
header("Location: index.php");
       exit();
    }
   
$_SESSION['set_admin'] = false;
   
header("Location: index.php");
    exit();
}

?>