PHP 表单助手类

发布于 2024-11-18 08:09:30 字数 1539 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

风铃鹿 2024-11-25 08:09:30

几个月前,我的一个项目需要类似的东西,但必须自己构建一个。您可以浏览源代码并下载帮助程序 https://github.com/mawuli- ypa/Php-html-class。示例:

  $html = new html;  
  // OR $html = new html('div',array('id'=>'iv id here','class'=>'div class here','text'=>'div contents here'))


   //create basic elements
  $html->create("h1",array('text'=>"mawuli-ypa","class"=>"big","style"=>"font-    size:30px"));
  $html->create("h1",array('text'=>"@koceptone.com","class"=>"big","style"=>"font-size:20px"));

表单:

 $html->create("form",array("enctype"=>"","multipart/form-data","method"=>"POST","action"=>"upload.php"));
 /* now render elements */
 $html->buildAll();

这是一个实验性的助手,但非常有用。该助手将很快更新。

I needed something similar for a project some months ago, but had to build one myself. You can browse the source code and download the helper at https://github.com/mawuli-ypa/Php-html-class. Example:

  $html = new html;  
  // OR $html = new html('div',array('id'=>'iv id here','class'=>'div class here','text'=>'div contents here'))


   //create basic elements
  $html->create("h1",array('text'=>"mawuli-ypa","class"=>"big","style"=>"font-    size:30px"));
  $html->create("h1",array('text'=>"@koceptone.com","class"=>"big","style"=>"font-size:20px"));

Forms:

 $html->create("form",array("enctype"=>"","multipart/form-data","method"=>"POST","action"=>"upload.php"));
 /* now render elements */
 $html->buildAll();

This was an experimental helper but was quite useful. The helper will be updated soon.

何处潇湘 2024-11-25 08:09:30

这是我们在所有网站上使用的:CodeIgniter form_heper

This is what we use for all our websites: CodeIgniter form_heper

我们的影子 2024-11-25 08:09:30

我想推荐 ATK UI 中的 Form 类。该课程旨在实现以下目标:

  • 使用语义 UI 构建表单 HTML(支持垂直、水平、多列和自定义布局)
  • 与数据存储(SQL、NoSQL)直接集成、处理类型转换(例如日期、下拉列表) ,自动完成字段)。还验证。
  • PHP 和 JavaScript 事件之间的集成。您指定表单提交时发生的情况 - 重定向、重新加载、关闭模式等。
  • 可扩展性。支持文件上传,它与 Flysystem、自定义字段、审核等集成。

(更多信息文档

该实现不依赖于任何特定的全栈框架,因此可以在任何PHP项目中使用。还有也集成到wordpress

I'd like to recommend Form class from ATK UI. The class aims to do the following:

  • Build form HTML using Semantic UI (supporting vertical, horizontal, multi-column and custom layouts)
  • Direct integration with data storage (SQL, NoSQL), handle of type conversions (such as dates, drop-downs, auto-complete fields). Also validation.
  • Integration between PHP and JavaScript events. You specify what happens on form submission - redirect, reload, closing modal, etc.
  • Extensibility. There are support for file uploads which integrates with Flysystem, custom fields, audit and more.

(more info in the doc)

The implementation is not tied into any specific full-stack framework, so can be used in any PHP project. There is integration into wordpress too.

最美的太阳 2024-11-25 08:09:30

来自 Zend 框架的 Zend_Form。也许并不简单但功能强大。我认为不存在简单的类,因为整体形式可能变得非常复杂。

Zend_Form from the Zend Framework. Maybe not exactly simple yet powerful. I think there is no simple class because forms overall can become very complex.

月亮邮递员 2024-11-25 08:09:30

表格很复杂……它们就是如此。你从简单开始,然后你意识到你需要约束和验证。然后您意识到一个字段的可用性取决于另一字段的值,依此类推。如果您需要的只是简单性,那么编写您自己的表单字段标记并编写一些 PHP 来处理输入就不需要花费太多精力。这就是最简单的事情了。

Forms are complicated... they just are. You start simple and then you realize you need constraints and validation. Then you realize that the availability of one field depends on the value of another, and so on. If all you need is bare simplicity, then it shouldn't take much effort to write your own form field tags and write some PHP to process the input. That is about as simple as it's going to get.

自此以后,行同陌路 2024-11-25 08:09:30

我一直在使用这个库并且它工作得很好。

http://helpers.theframework.es/helper-form/examples/

use TheFramework\Helpers\HelperForm;
use TheFramework\Helpers\HelperLabel;
use TheFramework\Helpers\HelperInputText;
use TheFramework\Helpers\HelperSelect;

$arFields = [];

$oAux = new HelperLabel("txtNameId","My label for Name");
$oAux->add_class("custom-control");
$arFields[] = $oAux;

$oAux = new HelperInputText();
$oAux->add_class("col-4");
$oAux->add_class("form-control");
$oAux->add_extras("placeholder","Eg. Eduardo A. F.");
$oAux->set_id("txtNameId");
$oAux->set_name("txtName");
$arFields[] = $oAux;

$arFields["sel"] = new HelperSelect([""=>"choose...","one"=>"One","two"=>"Two","three"=>"Three"]);
$arFields["sel"]->add_class("form-control col-4");

$arFields["textarea"] = new TheFramework\Helpers\HelperTextarea();
$arFields["textarea"]->add_class("form-control");
$arFields["textarea"]->add_extras("placeholder","Your comments");
$arFields["textarea"]->set_id("txaComments");

$oForm = new HelperForm();
$oForm->add_class("col-6");
$oForm->add_style("border:1px dashed #4f9fcf;");
$oForm->add_style("padding:5px;");
$oForm->set_id("myForm");
$oForm->set_method("some_method");
$oForm->set_enctype("myEncType");
$oForm->add_controls($arFields);
$oForm->show();

I have been using this library and it works fine.

http://helpers.theframework.es/helper-form/examples/

use TheFramework\Helpers\HelperForm;
use TheFramework\Helpers\HelperLabel;
use TheFramework\Helpers\HelperInputText;
use TheFramework\Helpers\HelperSelect;

$arFields = [];

$oAux = new HelperLabel("txtNameId","My label for Name");
$oAux->add_class("custom-control");
$arFields[] = $oAux;

$oAux = new HelperInputText();
$oAux->add_class("col-4");
$oAux->add_class("form-control");
$oAux->add_extras("placeholder","Eg. Eduardo A. F.");
$oAux->set_id("txtNameId");
$oAux->set_name("txtName");
$arFields[] = $oAux;

$arFields["sel"] = new HelperSelect([""=>"choose...","one"=>"One","two"=>"Two","three"=>"Three"]);
$arFields["sel"]->add_class("form-control col-4");

$arFields["textarea"] = new TheFramework\Helpers\HelperTextarea();
$arFields["textarea"]->add_class("form-control");
$arFields["textarea"]->add_extras("placeholder","Your comments");
$arFields["textarea"]->set_id("txaComments");

$oForm = new HelperForm();
$oForm->add_class("col-6");
$oForm->add_style("border:1px dashed #4f9fcf;");
$oForm->add_style("padding:5px;");
$oForm->set_id("myForm");
$oForm->set_method("some_method");
$oForm->set_enctype("myEncType");
$oForm->add_controls($arFields);
$oForm->show();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文