Forms
|
|
|
|
<? /********************************************************************
* drop-down-menu - form field function.
* 6 function which return a drop-down-menu
* Syntax :
* - string textarea (string name, int rows, int cols, string value);
* - string radio (string name, string value, int checked);
* - string checkbox (string name, string value, int checked);
* - string textbox (string type, string name, int size, int maxlength, string value);
* - string button (array button, string name);
* - string form (string action, array hidden, string validate);
*
* You can add a listbox()-function in my previous posting
* to accomplish this snippet
*
* Copyright (C) 2001 Wibisono Sastrodiwiryo.
* This program is free software licensed under the
* GNU General Public License (GPL).
*
* CyberGL => Application Service Provider
* http://www.cybergl.co.id
* office@cybergl.co.id
*
* $Id: formage.php3,v 0.1 2001/04/25 21:6:31 wibi Exp $
*********************************************************************/
function textarea ($name, $rows=0, $cols=0, $value="") {
$result ="<textarea name="$name" cols="$cols" rows="$rows">";
$result.=$value;
$result.="</textarea>";
return $result;
}
function radio ($name, $value, $checked="") {
$result ="<input type=radio ";
$result.="name="$name" ";
$result.="value="$value" ";
if ($checked) {$result.="checked";}
$result.=">";
return $result;
}
function checkbox ($name, $value, $checked="") {
$result ="<input type=checkbox ";
$result.="name="$name" ";
$result.="value="$value" ";
if ($checked) {$result.="checked";}
$result.=">";
return $result;
}
function textbox ($type, $name, $size=0, $maxlength=0, $value="") {
$result ="<input type="$type" ";
$result.="name="$name" ";
$result.="size="$size" ";
$result.="maxlength="$maxlength" ";
if ($value) {$result.="value="$value"";}
$result.=">";
return $result;
}
function button ($button, $name) {
while (list($key,$val)=each($button)) {
$result.="<input type=submit name="$name" value="$val">n";
}
return $result;
}
function form ($action, $hidden=0, $validate="") {
$result="<form action="$action" method=post ";
if ($validate) {$result.="onsubmit="return $validate"";}
$result.=">n";
if ($hidden) {
while (list($key,$val)=each($hidden)) {$result.="<input type=hidden name="$key" value="$val">n";}
}
return $result;
} ?>
|
|
|
Usage Example
|
<? require("formage.php3"); $hidden[login]="wibi"; $action="script.php3"; $button=array("Update", "Delete", "Cancel");
echo form($action, $hidden); ?>
Name : <?echo textbox("text", "name", 20, 32, "Wibisono")?><p>
Password : <?echo textbox("password", "pass", 20, 32, "Wibi")?><p>
Notification : <?echo checkbox("notify", "1", 1)?><p>
Gender : <?echo radio("gender", "male", 1)?> Male,<?echo radio("gender", "female")?> Female<p>
Notification : <?echo checkbox("notify", "1", 1)?><p>
<?echo button($button, "submit");?> </form>
|
|
|
Rate This Script
|
|
|
|