PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Edson Melo de Souza   Error Fields   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: This is a example for use the ClassErroFields
Class: Error Fields
Mark invalid form fields with special CSS styles
Author: By
Last change:
Date: 12 years ago
Size: 1,311 bytes
 

Contents

Class file image Download
<style type="text/css">
    .erro { border:solid 2px #ff0000; height: 22px; }
</style>

<?
include 'ClassErrorFields.php';
$error = new ClassErrorFields();

/* If the setter is activate, the setStr_Style() is not used */
$error->setStr_class('erro');

/* If not set this, the default value is taken */
$error->setStr_Style('style="border:solid 1px #ff0000; height: 22px;"');

/* Check the fields if completed. You can use other methods for make a test */
if (isset($_POST['btSend'])) {
   
/* Check here the fields posted and fill array to configure erros */

   
if ($_POST['fieldName1'] == '') {
       
$array_err .= 'fieldName1,';
    }

    if (
$_POST['fieldName2'] == '') {
       
$array_err .= 'fieldName2,';
    }
}
?>

<form id="form" method="post" action="<?php $PHP_SELF; ?>" >
    <p>First Field</p>
    <input type="text" name="fieldName1" id="fildName1" title="Anyway1"
           <? echo $error->showFieldError($array_err, 'fieldName1'); ?>
           value="<?= $_POST['fieldName1']; ?>" />

    <p>Second Field</p>
    <input type="text" name="fieldName2" id="fildName2" title="Anyway2"
           <? echo $error->showFieldError($array_err, 'fieldName2'); ?>
           value="<?= $_POST['fieldName2']; ?>" />
    <br /><br />
    <input name="btSend" type="submit" value="Send" />
</form>