<?php
/****************************************************************************************************
* Script: generator.class.php
* Package: HTML FORM FIELDS GENERATOR
* Author: Asokan Sivasubramanian
* Contact: asokan.zil016@gmail.com
* Date: September 8th, 2009
* Version: 1.0
*
*
* Notes:
* (1) Read Notes Before Listed Methods.
* (2) Support php4 / php5
*
*
* Purpose:
* - Easily handle Textbox, Text area, Option Box, Check box, Radio box
* - Reduce developer complicity
* - Reduce code & execution time
*
***************************************************************************************************/
Class Generator {
function Generator(){
//initiate auto consutuctor
}
//Create a text box
/*
* INPUT ARGUMENTS
* $fld_type - input type mentioned, text default, can change password also
* $fld_name - name of the field controller
* $fld_val - value of the field
* $max_len - maximum length allowed
*
* RETURN
* Text box with ( name, type, value, MAXLENGTH ) Properties
*
********************************************************************/
function create_textbox($fld_type='text',$fld_name,$fld_val,$max_len=20){
$frm_tag ="<input type ='$fld_type' name='$fld_name' value='$fld_val' MAXLENGTH='$max_len'>";
return $frm_tag;
}
//Create a text area
/*
* INPUT ARGUMENTS
* $fld_name - name of the field controller
* $fld_val - value of the field
* $rows - No.of rows displayed
* $cols - No.of columns displayed
*
* RETURN
* Text Area with ( name, rows, cols, value ) Properties
*
********************************************************************/
function create_textarea($fld_name,$fld_val,$rows=4,$cols=6){
$frm_tag ="<TEXTAREA name='$fld_name' rows='$rows' cols='$cols'>$fld_val</TEXTAREA>";
return $frm_tag;
}
//Create a option box
/*
* INPUT ARGUMENTS
* $fld_name - name of the field controller
* $input_array - Listed details, given a array format of input
* $selected - Selected value
* $style - Choose witdh of the box, 200px as default
*
* RETURN
* Option Box with ( key, value, Selected ) Properties
*
********************************************************************/
function create_optionbox($fld_name,$input_array,$selected,$style='width=200px'){
$frm_tag .="<select name='$fld_name' style='$style'>";
$frm_tag .="<option value='0'>CHOOSE ANY ONE </option>";
foreach($input_array as $key=>$value){
if($key == $selected){
//EX; $frm_tag .="<option value = '202' SELECTED>INDIA</option>";
$frm_tag .="<option value = '$key' SELECTED>$value</option>";
}else{
$frm_tag .="<option value = '$key'>$value</option>";
}
}
$frm_tag .="</select>";
return $frm_tag;
}
//Create a check box
/*
* INPUT ARGUMENTS
* $fld_name - name of the field controller
* $input_array - Listed details, given a array format of input
* $selectedlist - Selected value
* $num_rows - No.of checkbox diaplayed in single row
*
* RETURN
* Option Box with ( checkbox, label, Checked ) Properties
*
********************************************************************/
function create_checkbox($fld_name='fld_name',$input_array,$selectedlist,$num_rows=1){
$a_selectedlist = split(",",$selectedlist);
$table_list.="<table width=100% border=0><tr width=100%>";
foreach($input_array as $k=>$v){
$chkvalue="";
if ($a_selectedlist){
if (in_Array($k,$a_selectedlist)) $chkvalue="checked";
}
$table_list.="<td width=33% class=checkbox_td colspan=$num>
<input type=checkbox name=".$fld_name."[] value=$k id=$fld_name$k $chkvalue class=checkbox> ".ucwords(strtolower($v))."<label for=".$fld_name.$input_array[1]."></label>
</td>";
$i++;
if ($i%$num_rows==0) $table_list .="</tr><tr>";
}
$table_list .="</tr></table>";
return $table_list;
}
//Create a radio box
/*
* INPUT ARGUMENTS
* $fld_name - name of the field controller
* $input_array - Listed details, given a array format of input
* $selectedlist - Selected value
* $num_rows - No.of checkbox diaplayed in single row
*
* RETURN
* Option Box with ( radio, label, Checked ) Properties
*
********************************************************************/
function create_radiobox($fld_name,$input_array,$selectedlist,$num_rows=1){
$a_selectedlist = split(",",$selectedlist);
$table_list.="<table width=100% border=0><tr width=100%>";
foreach($input_array as $k=>$v){
$chkvalue="";
if ($a_selectedlist){
if (in_Array($k,$a_selectedlist)) $chkvalue="checked";
}
$table_list.="<td width=33% class=checkbox_td colspan=$num>
<input type=radio name=".$fld_name."[] value=$k id=$fld_name$k $chkvalue class=checkbox> ".ucwords(strtolower($v))."<label for=".$fld_name.$input_array[1]."></label>
</td>";
$i++;
if ($i%$num_rows==0) $table_list .="</tr><tr>";
}
$table_list .="</tr></table>";
return $table_list;
}
}//EndClass
?>
|