Update of /cvsroot/openfirst/config/functions
In directory sc8-pr-cvs1:/tmp/cvs-serv4312
Added Files:
forms.php
Log Message:
Created functions folder and added forms.php within the folder. forms.php contains two functions for checking and displaying errors within the openFIRST modules.
--- NEW FILE: forms.php ---
<?php
/*
* openFIRST globals.php
* Last Modified:
* David Di Biase, April 13, 2003
*
* Copyright (C) 2003,
* openFIRST Project
* Original Author: Tim Ginn <tim...@po...>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
// Set function information
function checkform($field){
$error = array();
// Loop through every single array in the function
foreach($field as $fields=>$checkwith){
// While looping use one of these cases to perform the proper checking
switch($checkwith){
// If field is a password then check as password and respond
case "password":
if(strlen($_POST[$fields]) < 5){
$error[] = "Password is too short, must be 5-6 characters in length. You entered: ".$_POST[$fields];
}
break;
// If field is an email address then check as email and respond
case "email":
if( ! eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@([a-z0-9]+([\.-][a-z0-9]+))*$",$_POST[$fields])){
$error[] = "E-mail field contains illegal characters. You entered: ".$_POST[$fields];
} else {
$item = explode("@", $_POST[$fields]);
if( gethostbyname($item["1"]) == $item["1"]) {
$error[] = "Domain in e-mail address is illegal. You entered: ".$_POST[$fields];
}
}
break;
// If field is set as ifempty then check if its empty and respond
case "ifempty":
if(empty($_POST[$fields])){
$error[] = "Empty field on form. You entered: ".$_POST[$fields];
}
}
}
return $error;
}
// Set function values
function formerrors($error){
// Check if requires error response
if (! empty($error)){
// Create errors table
echo "<table width=400 border=1 align=center cellpadding=1 cellspacing=0 bordercolor=#333333 bgcolor=#CCCCCC><tr><td><b>You have errors within your form:</b><br>";
// Display errors in form
foreach($error as $value){
echo "- ".$value."<br>";
}
// Close errors table
echo "</td></tr></table>";
}
}
?>
|