php表单⾃动⽣成,PHP⾃动⽣成表单代码分享Form.php
//Form.php
classform{
var$layout=true;//是否使⽤表格布局
var$action;//表单要提交到的URL
var$method;
var$enctype="";
var$name="";
var$id="";
var$class="";
functionform($action,$method="POST"){//通过构造函数初始化成员变量
$this->action=$action;
$this->method=$method;
}
functionform_start(){
$text="action}"method="{$this->method}"";
if($this->class!==""){
$text.="class="{$this->class}"";
}
if($this->enctype!==""){
$text.="enctype="{$this->enctype}"";
}
if($this->id!==""){
$text.="id="{$this->id}"";
}
if($this->name!==""){
$text.="name="{$this->name}"";
}
$text.=">n";
if($this->layout==true){
$text.="
}
return$text;
functionform_end(){
if($this->layout==true){
$text="t
n";
$text.="n";
}else{
$text="n";
}
return$text;
}
//⽂本框函数
functionform_text($name,$id,$label_name,$label_for,$value=""){ $text="
$text.="id="{$id}"";
if(isset($value)){
$text.="value="{$value}"";
}
$text.="/>n";
$label=$this->form_label($label_name,$label_for);
$form_item=$this->form_item($label,$text);
return$form_item;
}
//密码框函数
functionform_passwd($name,$id,$label_name,$label_for,$value=""){ $text="
$text.="id="{$id}"";
if(isset($value)){
$text.="value="{$value}"";
}
$text.="/>n";
$label=$this->form_label($label_name,$label_for);
$form_item=$this->form_item($label,$text);
return$form_item;
//隐藏域函数
functionform_hidden($name,$id,$label_name,$label_for,$value=""){
$text="
if(isset($value)){
$text.="value="{$value}"";
}
$text.="/>n";
$label=$this->form_label($label_name,$label_for);
$form_item=$this->form_item($label,$text);
return$form_item;
}
//⽂件域函数
functionform_file($name,$id,$label_name,$label_for,$size=""){
$text="
$text.="id="{$id}"";
if(isset($size)){
$text.="size="{$size}"";
}
$text.="/>n";
$label=$this->form_label($label_name,$label_for);
$form_item=$this->form_item($label,$text);
return$form_item;
}
//复选框函数
functionform_checkbox($name,$label=array(),$label_name,$label_for=""){ $i=0;
$text=array();
foreach($labelas$id=>$value){
$text[$i]="";
$text[$i].="{$value}";
$i++;
}
$label=$this->form_label($label_name,$label_for);
$form_item=$this->form_item($label,$text);
return$form_item;
}
/
/单选框函数表格网站php源码
functionform_radio($name,$label=array(),$label_name,$label_for=""){
$i=0;
$text=array();
foreach($labelas$id=>$value){
$text[$i]="";
$text[$i].="{$value}";
$i++;
}
$label=$this->form_label($label_name,$label_for);
$form_item=$this->form_item($label,$text);
return$form_item;
}
//下拉菜单函数
functionform_select($id,$name,$options=array(),$selected=false,$label_name,$label_for,$οnchange=""){ if($onchange!==""){
$text="n";
}
else{
$text="n";
}
foreach($optionsas$value=>$key){
if($selected==$value){
$text.="t{$key}n";
}elseif($selected===false){
$text.="t{$key}n";
}
}
$text.="";
$label=$this->form_label($label_name,$label_for);
$form_item=$this->form_item($label,$text);
return$form_item;
}
//多选列表函数
functionform_selectmul($id,$name,$size,$options=array(),$label_name,$label_for){ $text="n";
foreach($optionsas$value=>$key){
$text.="t{$key}n";
}
$text.="n";
$label=$this->form_label($label_name,$label_for);
$form_item=$this->form_item($label,$text);
return$form_item;
}
//按钮函数
functionform_button($id,$name,$type,$value,$οnclick=""){
$text="
if($onclick!==""){
$text.="οnclick='{$onclick}'";
}
$text.=">".$value;
$text.="n";
if($this->layout==true){
$form_item="
nt{$text}nn";
}else{
$form_item=$text;
}
return$form_item;
}
//⽂本域函数
functionform_textarea($id,$name,$cols,$rows,$label_name,$label_for,$value=""){ $text="{$value}n";
$label=$this->form_label($label_name,$label_for);
$form_item=$this->form_item($label,$text);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。