libraries for building HTML form using PHP -
i'm looking building html form using php wondering may libraries exist. know open source library can use ?
do think, it's idea create function construct html form using php ? there risk on performance (loading pages of website) ?
function input($label,$id,$type) { echo $label.' <input type="'.$type.'" id="'.$id.'" name="'.$id.'" />'; } input('user name','login','text');
my purpose build library maitain code.
i have couple of functions created in days. use them projects, not framework dependent. nowadays prefer using symfony's form component when possible.
take look, give idea.
function lb($text, $forid='', $style='', $attr='') { if($style!='') $style='style="'.$style.'"'; if($forid!='') $forid='for="'.$forid.'"'; return '<label '.$style.$forid.' '.$attr.'>'.$text.'</label>'; } //generates input field, , populates inputs. edit forms too. function in($name, $cust_val='', $style='', $attr='', $set_id=true) { global $edit; $val=''; if(isset($edit[$name])) $val=$edit[$name]; if($cust_val!='') { $val=$cust_val; } if($style!='') $style='style="'.$style.'"'; $setid=''; if($set_id) $setid="id=\"".$name."\""; return '<input type="text" name="'.$name.'" '.$setid.' '.$attr.' '.$style.' value="'.ht($val).'">'; } /* * prints multiple <td></td> table structure * * @param array vals - values used inside tds * @param boolean encloseintr when true puts <tr> outside tds */ function tds($vals, $encloseintr=false) { $out=''; foreach($vals $v) { $out.='<td>'.$v.'</td>'; } if($encloseintr) $out = '<tr>'.$out.'</tr>'; return $out; } /* * prints multiple <th></th> table structure * * @param array vals - values used inside ths * @param boolean $encloseinthead when true puts <thead> outside th * @param class class var added th */ function ths($vals, $encloseinthead=false, $class='') { $out=''; foreach($vals $v) { if($class!='') $out.='<th class="'.$class.'">'.$v.'</th>'; else $out.='<th>'.$v.'</th>'; } if($encloseinthead) $out = '<thead>'.$out.'</thead>'; return $out; } //alias htmlspecialchars function ht($string) { return htmlspecialchars($string,ent_quotes); }
and how form code like:
$form = form_start(..) .lb('first name','') .in('name','','width:400px;') .lb('telefon','').cl() .in('tel','','width:400px;') //... .form_end() ;
Comments
Post a Comment