首页 > 其他分享 >Web表单生成器--转摘-守护那份情,给自己学习用。侵权情通知,会删。

Web表单生成器--转摘-守护那份情,给自己学习用。侵权情通知,会删。

时间:2022-11-19 22:36:28浏览次数:40  
标签:Web attr -- text 生成器 item html input tag

 在项目的实际开发中,经常需要设计各种各样表单。直接编写HTML表单虽然简单,但修改、维护相对麻烦。
   因此,可以利用PHP实现一个Web表单生成器,使其可以根据具体的需求定制不同功能的表单。具体实现需求如下:

  数据的保存形式决定了程序实现的方式。
  因此,根据上述开发要求,可以将每个表单项作为一个数组元素,每个元素利用一个关联数组描述,分别为:标记tag、提示文本text、属性数组attr、选项数组option和默认值default。
————————————————
版权声明:本文为CSDN博主「守护那份情」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zjs_csdns/article/details/88853665

 

php源代码如下:

1)数据层

<?php
$date = [
[
"text" =>"姓 名:",
"tag" =>"input",
"attr" =>['type'=>'text','name'=>'username']
],
[
"text" =>"账 号:",
"tag" =>"input",
"attr" =>['type'=>'text','name'=>'username']
],
[
"text" =>"密 码:",
"tag" =>"input",
"attr" =>['type'=>'password','name'=>'pwd']
],
[
"text" =>"邮 箱:",
"tag" =>"input",
"attr" =>['type'=>'text','name'=>'email']
],
[
"text" =>"电 话:",
"tag" =>"input",
"attr" =>['type'=>'text','name'=>'tel']
],
[
'tag' => 'input',
'text' => '性  别:',
'attr' => ['type' => 'radio', 'name' => 'gender'],
'option' => ['m' => '男', 'w' => '女']
],
[
'tag' => 'select',
'text' => '住  址:',
'attr' => ['name' => 'area'],
'option' => [
'' => '--请选择--',
'BJ' => '北京',
'SH' => '上海',
'SZ' => '深圳',
'CQ' => '重庆',
'TJ' => '天津',
'HB' => '河北',
'SD' => '山东',
'LN' => '辽宁',
'HLJ' => '黑龙江',
'JL' => '吉林',
'GS' => '甘肃',
'QH' => '青海',

]
],
[
'tag' => 'textarea',
'text' => '自我介绍:',
'attr' => ['name' => 'declare', 'cols' => '50', 'rows' => '5']
]
];
?>

 

2)编辑层

<?php
include "date.php";
function ent(){
global $date;
$html= "";
foreach ($date as $item){
if($item['tag']=='input'){
//生成input标签函数
$html=$html.input_html($item);
}
else if($item['tag']=='select'){
//生成下拉列表标签函数
$html=$html.select_html($item);
}
else if($item['tag']=='textarea'){
//生成多行文本
$html=$html.textarea_html($item);
}
}
return $html;
}
function input_html($item){
$html = "";
if($item['attr']['type']=='text'){
//生成文本框
$html = $item['text']."<input type='{$item['attr']['type']}' name='{$item['attr']['name']}'>";
}
else if($item['attr']['type']=='radio'){
//生成单选按钮

$html = $item['text'];
$html = $html."<input type='{$item['attr']['type']}' name='{$item['attr']['name']}' value='{$item['option']['m']}'>{$item['option']['m']}";
$html = $html."<input type='{$item['attr']['type']}' name='{$item['attr']['name']}' value='{$item['option']['w']}'>{$item['option']['w']}";
}else if($item['attr']['type']=='password'){
$html = $item['text']."<input type='{$item['attr']['type']}' name='{$item['attr']['name']}'>";
}
return $html.'<p></p>';
}
function select_html($item){
$html="";
$html=$item['text'];
$html.="<select>";
foreach ($item['option'] as $v){
$html.="<option value='$v'>$v</option>";
}
$html.="</select>";
return $html.'<p></p>';
}
function textarea_html($item){
$html="";
$html=$item['text'];
$html.="<textarea cols='{$item['attr']['cols']}' rows='{$item['attr']['rows']}'></textarea>";
return $html;
}

 

3)表示层

 

<?php
include "function.php";
echo ent();

标签:Web,attr,--,text,生成器,item,html,input,tag
From: https://www.cnblogs.com/tomcat2022/p/16907363.html

相关文章

  • AtCoder Beginner Contest 278题解
    A-Shift题意给一个长度为\(n\)的数组,有\(k\)次操作,每次操作会将数组最前面的元素删掉,再在数组最后面加上一个0元素,问\(k\)次操作后的数组中的数字。思路看\(n\)与\(k......
  • java.lang.OutOfMemoryError: PermGen space
    可能是自己的系统写的比较烂,三个系统一起跑过几天就出现内存溢出,从网上查了一下,这类问题应该先进行code修改。PermGenspace的全称是PermanentG......
  • AJAX
    1、概念AJAX:异步的JavaScript和XML2、AJAX作用:(1)与服务器进行数据交换:通过AJAX可以给服务器发送请求,并获取服务器响应的数据。    使用了AJAX和服务器进行通信,就......
  • java——集合——Map集合——Map接口中的常用方法
    Map接口中的常用方法Map接口中定义了很多方法,常用的如下:publicVput(Kkey,Vvalue):把指定的键与指定的值添加到Map集合中。publicVremove(Objectkey):把......
  • jbpm 常用代码及 jbpm IdentityService 扩展
    一、流程定义1.部署流程定义ProcessEngineprocessEngine=newConfiguration().buildProcessEngine();RepositoryServicerepositoryService=......
  • npm 发布注意事项
    镜像需切换回registry镜像npmconfigsetregistryhttps://registry.npmjs.org/更新完毕后可切换回淘宝镜像npmconfigsetregistryhttps://registry.npm.taobao.or......
  • Devpress 小技巧1
    列单选事件1.CheckEdit.Properties.CheckStyle=DevExpress.XtraEditors.Controls.CheckStyles.Radio;intcheckedRowIndex=-1;privatevoidgridView1_Cel......
  • velocity语法介绍
    TheVelocityTemplateLanguage(VTL)目标是提供一个简洁,易学的方法将动态内容展现到webpage上.awebpage设计者可以没有任何编程经验就可以在......
  • mongodb windows 安装以及资料
    mongoDBwindows安装1:下载http://www.mongodb.org/display/DOCS/Downloads选择你要下载的版本解压软件包,你会看到解压后的文件夹中有个BIN目录,进......
  • Django Rest_Framework(一)
    GIT操作远程仓库推送代码凭证管理'初到公司,先克隆远程仓库的代码gitclonehttps://gitee.com/clschao/ttt.git将整个远程仓库的代码\分支\版本都拷贝到了......