| TlcAndres |
12-13-2007 09:01 PM |
Form Function
Just wanted some thoughts on the the efficiency of this function
PHP Code:
function FormGenerate($frmname,$to,$values=array(),$echo=false,$len='30',$submitto='',$special=array())
{
//set up the form and create the action
$submit = !empty($submitto) ? "onSubmit='".$submitto."'" : '';
$data = '<form name="'.$frmname.'" method="post" action="'.$this->siteinfo['url'] . $to.'" '.$submit.'>
<table>';
$tag = reset(array_keys($special));
$rep = reset($special);
//start the loop, this method is supposed to be more efficient
while(list(, $v) = each($values))
{
$type = ($v == $tag) ? $rep : 'text';
//create the table and such
$data .= '
<tr>
<td><label for="'.$v.'">'.$v.'</label><td>
<td><input name="'.$v.'" id="'.$v.'" value="" size="'.$len.'" maxlength="255" type="'.$type.'"></td>
</tr>';
$tag = sizeof(array_keys($special)) > 1 ? next(array_keys($special)) : $tag;
$rep = sizeof($special) > 1 ? next($special) : $rep;
}
//finish it all off
$data .= '<tr><td><input value="submit" type="submit"></td></tr></table>';
//return it all
if($echo) { echo($data); }else{ return $data; }
}
|