PHP automatically generate form code share, PHP automatically generate form _php tutorial

Source: Internet
Author: User

PHP automatically generate form code sharing, PHP automatically generate forms


form.php

<?php//form.phpclass form {var $layout =true;//whether to use table layout var $action;//The URL to which the form is to be submitted Var $method;    var $enctype = "";    var $name = "";    var $id = "";    var $class = "";        function form ($action, $method = "POST") {//Initialize member variables by constructor $this->action= $action;    $this->method= $method;        } function Form_start () {$text = "\ n"; }else {$text = "\ n ";    } return $text; }//text box function Form_text ($name, $id, $label _name, $label _for, $value = "") {$text = "Form_label ($label _name, $label _for);        $form _item= $this->form_item ($label, $text);    return $form _item; }//Password box function form_passwd ($name, $id, $label _name, $label _for, $value = "") {$text = "Form_label ($label _name, $label _for);        $form _item= $this->form_item ($label, $text);    return $form _item; }//Hide domain functions function form_hidden ($name, $id, $label _name, $label _for, $value = "") {$text = "Form_label ($label _name, $label _for);        $form _item= $this->form_item ($label, $text);    return $form _item; }//File domain functions function form_file ($name, $id, $label _name, $label _for, $size = "") {$text = "Form_label ($label _name, $label _for);        $form _item= $this->form_item ($label, $text);    return $form _item;        }//check box functions function Form_checkbox ($name, $label =array (), $label _name, $label _for= "") {$i = 0;        $text =array (); foreach ($label as $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;        }//Radio box functions function Form_radio ($name, $label =array (), $label _name, $label _for= "") {$i = 0;        $text =array (); foreach ($label as $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;        }//drop-down menu functions function Form_select ($id, $name, $options =array (), $selected =false, $label _name, $label _for, $onchange = "") { if ($onchange!== "") {$text = "\ n "; } else{$text = "\ n "; } foreach ($options as $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; }//multi-select list function Form_selectmul ($id, $name, $size, $options =array (), $label _name, $label _for) {$text = "\ n "; foreach ($options as $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; }//Button function Form_button ($id, $name, $type, $value, $onclick = "") {$text = "Layout==true) {$form _item= "\n\t {$text}\ n\ n ";        }else {$form _item= $text;    } return $form _item; }//Text field functions function Form_textarea ($id, $name, $cols, $rows, $label _name, $label _for, $value = "") {$text = "<textarea id="\"{$id}\"" name="\"{$name}\"" cols="\"{$cols}\"" rows="\"{$rows}\"">{$value}</textarea>\ n ";        $label = $this->form_label ($label _name, $label _for);        $form _item= $this->form_item ($label, $text);    return $form _item; }//Text label function Form_label ($text, $for) {if ($for!== "") {$label = "{$text}:"; }else {$label = $text. "        :";    } return $label; } function Form_item ($form _label, $form _text) {switch ($this->layout) {case true: $t Ext= "\ n "; $text. = "\ t";                $text. = $form _label; $text. = "\ n "; $text. = "\ t";                $text. = $form _text; $text. = "\ n "; $text. = "\ n ";            Break                Case false: $text = $form _label;                $text. = $form _text;        Break    } return $text;        } function CreateForm ($form _item=array ()) {echo $this->form_start ();        foreach ($form _item as $item) {echo $item;    } echo $this->form_end (); }}?>

Examples of Use:

    
 
      
 
      User Login<?phprequire_once ("form.php"), $form =new form ($_server[' php_self ']);   Submit to this page $form->layout=false;                   Without using the table layout, you can comment out the differences in the results $name= $form->form_text ("userid", "userid", "username", "userid"), $passwd = $form->form_ passwd ("passwd", "passwd", "Password", "passwd"), $submit = $form->form_button ("", "submit", "Submit", "Login"); $form _item= Array ($name, $passwd, $submit); $form->createform ($form _item);? >

The above mentioned is the whole content of this article, I hope you can like.

http://www.bkjia.com/PHPjc/1019455.html www.bkjia.com true http://www.bkjia.com/PHPjc/1019455.html techarticle PHP automatically generated form code sharing, PHP automatically generated form form.php php//form.phpclass form {var $layout =true;//use table layout var $action;//URL to which the form is to be submitted var ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.