Php > Php Classes
Form is a utility class for generating html forms. It provides form initialization
Form is a utility class for generating html forms. It provides form initialization and regex based data validation (both server and client side) with a convenient interface elements[current($deflist)]; } else { reset($this->elements); $el = current($this->elements); } while ($el) { if (!($eltype = $el[ "type"])) { $el = current($el); $eltype = $el[ "type"]; } $elname = $el[ "name"]; global $$elname; $elval = $$elname; switch ($eltype) { case "text": case "pass": case "textarea": $this->elements[$elname][ "value"] = $elval; break; case "checkbox": if (isset($elval)) $this->elements[$elname][ "checked"] = "yes"; else $this->elements[$elname][ "checked"] = "no"; break; case "radio": reset ($this->elements[$elname]); while ($temp = current($this->elements[$elname])) { $temp[ "checked"] = "no"; next($this->elements[$elname]); } $this->elements[$elname][$elval][ "checked"] = "yes"; break; case "select": case "select multiple": $this->elements[$elname][ "value"] = $elval; $elops = $this->elements[$elname][ "options"]; if (is_array($elops)) { reset($elops); $elops = current($elops); if (isset($this->elements[$elname][ "valid_e"]) && !((is_array($elops) && (($elops[ "label"] == $elval) || ($elops[ "value"] == $elval))) || ($elops == $elval))) { myunset(&$this->elements[$elname][ "options"],0); unset($this->elements[$elname][ "valid_e"]); } } break; } if ($deflist) { next($deflist); $el = $this->elements[current($deflist)]; } else { next($this->elements); $el = current($this->elements); } } } function start($jsv_name= "",$method= "",$action= "",$target= "") { global $PHP_SELF; if (!$method) $method = "POST"; if (!$action) $action = $PHP_SELF; if (!$target) $target = "_self"; if ($jsv_name) { echo "\n"; echo "
\n"; } else echo "
"; } function finish() { if ($this->hidden) { reset($this->hidden); while ($elname = current($this->hidden)) { $elval = $this->elements[$elname][ "value"]; echo "
\n"; next($this->hidden); } } echo "
\n"; } function validate($default,$vallist= "") { if ($vallist) { reset($vallist); $el = $this->elements[current($vallist)]; } else { reset($this->elements); $el = current($this->elements); } while ($el) { if (!$el[ "type"]) $el = current($el); $elname = $el[ "name"]; $eltype = $el[ "type"]; global $$elname; $elval = $$elname; switch ($eltype) { case "text": case "password": $el_e = $el[ "length_e"]; if (($elmin = $el[ "min_l"]) && strlen($elval) < $elmin) return $el_e; $elreg = $el[ "valid_regex"]; if (($el_e = $el[ "valid_e"]) && !ereg($elreg,$elval)) return $el_e; break; case "radio": if (($el_e = $el[ "valid_e"]) && !$elval) return $el_e; break; case "select": if ($el_e = $el[ "valid_e"]) { $elops = $el[ "options"]; reset($elops); $elops = current($elops); if (is_array($elops)) $elops = $elops[ "value"]; if ($elval == $elops) return $el_e; } break; } if ($vallist) { next($vallist); $el = $this->elements[current($vallist)]; } else { next($this->elements); $el = current($this->elements); } } return($default); } function add_element($el) { if (($el[ "type"] != "radio") && ($el[ "type"] != "submit")) $this->elements[$el[ "name"]] = $el; else $this->elements[$el[ "name"]][$el[ "value"]] = $el; if ($el[ "type"] == "hidden") $this->hidden[] = $el[ "name"]; } function show_element($name,$value= "") { if ($value) $el = $this->elements[$name][$value]; else $el = $this->elements[$name]; $eltype = $el[ "type"]; $elname = $el[ "name"]; $elvalue = $el[ "value"]; $elextrahtml = $el[ "extra_html"]; switch ($eltype) { case "text": case "password": echo "
\n"; break; case "image": echo "
\n"; break; case "checkbox": case "radio": if (($elchk = $el[ "checked"]) && $elchk != "no") $elextrahtml .= " checked"; case "hidden": case "submit": case "reset": echo "
\n"; break; case "textarea": $elrows = $el[ "rows"]; $elcols = $el[ "cols"]; $elwrap = $el[ "wrap"]; echo "
\n"; echo "$elvalue"; echo ""; break; case "select": case "select multiple": $elsize = $el[ "size"]; $elops = $el[ "options"]; echo "<$eltype name=\"$elname"; if ($eltype == "select multiple") echo "[]\""; else echo "\""; if ($elsize) echo " size=\"$elsize\""; echo " $elextrahtml>\n"; if (is_array($elops)) while ($curop = current($elops)) { echo "
$curop
\n"; next($elops); } echo "\n"; break; } } } ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage