PHP automatically generates form code sharing, php automatically generates forms

Source: Internet
Author: User

PHP automatically generates form code sharing, php automatically generates forms

Form. php

<? Php // Form. phpclass form {var $ layout = true; // whether to use table layout var $ action; // URL var $ method to be submitted to the form; var $ enctype = ""; var $ name = ""; var $ id = ""; var $ class = ""; function form ($ action, $ method = "POST ") {// initialize the member variable $ this-> action = $ action; $ this-> method = $ method;} function form_start () through the constructor () {$ text = "<form action = \" {$ this-> 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. = "<table> \ n";} return $ text;} function form_end () {if ($ this-> layout = true) {$ text = "\ t </table> \ n"; $ text. = "</form> \ n";} else {$ text = "</form> \ n";} return $ text ;} // text box function form_text ($ name, $ id, $ label_name, $ label_for, $ value = "") {$ text = "<input type = \" text \ "name = \" {$ name} \ ""; $ 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;} // Password box function form_passwd ($ name, $ id, $ label_name, $ label_for, $ value = "") {$ text = "<input type = \" password \ "name = \" {$ name} \ ""; $ 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 ;} // hide the Domain function form_hidden ($ name, $ id, $ label_name, $ label_for, $ value = "") {$ text = "<input type = \" hidden \ "name = \" {$ name} \ "id = \" {$ id }\""; if (isset ($ value) {$ text. = "value = \" {$ value} \ "";} $ text. = "/> \ n"; $ label = $ this-> form_label ($ label_name, $ label_for); $ form_item = $ this-> form_item ($ label, $ tex T); return $ form_item;} // file Domain function form_file ($ name, $ id, $ label_name, $ label_for, $ size = "") {$ text = "<input type = \" file \ "name = \" {$ name} \ ""; $ 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;} // check box function form_checkbox ($ name, $ label = array (), $ la Bel_name, $ label_for = "") {$ I = 0; $ text = array (); foreach ($ label as $ id => $ value) {$ text [$ I] = "<input type = \" checkbox \ "id = \" {$ id} \ "name = \" {$ name} \ "value = \ "{$ value} \"/> "; $ text [$ I]. = "<label for = \" {$ id} \ ">{$ value} </label>"; $ I ++ ;} $ label = $ this-> form_label ($ label_name, $ label_for); $ form_item = $ this-> form_item ($ label, $ text); return $ form_item ;} // single functions form_radio ($ name, $ label = array (), $ label_n Ame, $ label_for = "") {$ I = 0; $ text = array (); foreach ($ label as $ id => $ value) {$ text [$ I] = "<input type = \" radio \ "id = \" {$ id} \ "name = \" {$ name} \ "value = \ "{$ value} \"/> "; $ text [$ I]. = "<label for = \" {$ id} \ ">{$ value} </label>"; $ I ++ ;} $ label = $ this-> form_label ($ label_name, $ label_for); $ form_item = $ this-> form_item ($ label, $ text); return $ form_item ;} // drop-down menu function form_select ($ id, $ name, $ options = array (), $ selecte D = false, $ label_name, $ label_for, $ onchange = "") {if ($ onchange! = "") {$ Text = "<select id = \" {$ id} \ "name = \" {$ name} \ "onchang = \" {$ onchange} \ "> \ n ";} else {$ text = "<select id = \" {$ id} \ "name = \" {$ name} \ "> \ n ";} foreach ($ options as $ value => $ key) {if ($ selected = $ value) {$ text. = "\ t <option valute = \" {$ value} \ "selected = \" selected \ ">{$ key} </option> \ n ";} elseif ($ selected === false) {$ text. = "\ t <option value = \" {$ value} \ ">{$ key} </option> \ n" ;}}$ text. = "</select>"; $ label = $ th Is-> form_label ($ label_name, $ label_for); $ form_item = $ this-> form_item ($ label, $ text); return $ form_item ;} // multiple choice list function form_selectmul ($ id, $ name, $ size, $ options = array (), $ label_name, $ label_for) {$ text = "<select id = \" {$ id} \ "name = \" {$ name} \ "size = \" {$ size} \ "multiple = \ "multiple \"> \ n "; foreach ($ options as $ value => $ key) {$ text. = "\ t <option value = \" {$ value} \ ">{$ key} </option> \ n" ;}$ text. = "</select> \ 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 = "<button id = \" {$ id} \ "name = \" {$ name} \ "type = \" {$ type }\""; if ($ onclick! = "") {$ Text. = "onclick = '{$ onclick}'";} $ text. = "> ". $ value; $ text. = "</button> \ n"; if ($ this-> layout = true) {$ form_item = "<tr> \ n \ t <th> </th> <td >{$ text} </td> \ n </tr> \ n ";} else {$ form_item = $ text;} return $ form_item;} // function of the text Domain 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;} // The function form_label ($ text, $ for) {if ($! = "") {$ Label = "<label for = \" {$ for} \ ">{$ text }:</label> ";} else {$ label = $ text. ":";} return $ label;} function form_item ($ form_label, $ form_text) {switch ($ this-> layout) {case true: $ text = "<tr> \ n"; $ text. = "\ t <th class = \" label \ ">"; $ text. = $ form_label; $ text. = "</th> \ n"; $ text. = "\ t <td>"; $ text. = $ form_text; $ text. = "</td> \ n"; $ text. = "</tr> \ 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 () ;}}?>

Example:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

The above is all the content of this article. I hope you will like it.

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.