Zend - The PHP Company




Forms

Add Code


Formage  

Type: code fragment
Added by: wibi
Entered: 20/05/2001
Last modified: 05/12/2000
Rating: **** (3 votes)
Views: 10495
A complete formfield function minus listbox function, you can make textbox, radio button, checkbox, textarea, button and form opening function.

You can obtain listbox function from my previous posting
( another date drop-down-menu and make listbox from array or database-table )



<?
/********************************************************************
*    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"2032"Wibisono")?><p>
Password : <?echo textbox("password""pass"2032"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





Search



This Category All Categories