werx/forms 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

werx/forms

Composer 安装命令:

composer require werx/forms

包简介

Framework agnostic form helpers

README 文档

README

Build Status Total Downloads Latest Stable Version Code Climate

Framework agnostic form helpers.

About

I've never found form libraries terribly useful. In my experience, they either work only for the most simple forms, or end up being way more difficult to use than just writing the HTML by hand.

That said, I do need some really basic form helpers to easily pre-populate form fields (like from previous POST to correct errors or from a database) and build drop down boxes.

The primary goal of this library is to solve those 2 problems in a way I don't hate. If I can make some more robust form helpers that don't get in my way while I'm at it, all the better.

This library provides helpers for setting default values in otherwise static html form elements as well as an input builder for dynamically creating form elements.

Quick Examples

You can view the full documentation with more examples at http://werx.moody.io/packages/forms/

Here's a few quick examples to get you started.

<?php
use werx\Forms\Form;

Form::setData($_POST);
?>

Text boxes

<input type="text" name="username" id="username" value="<?=Form::getValue('username')?>">
<?=Form::text('username')?>

Selects

<select name="state">
	<option value="AR" <?=Form::getSelected('state', 'AR')?>>Arkansas</option>
	<option value="TX" <?=Form::getSelected('state', 'TX')?>>Texas</option>
	<option value="OK" <?=Form::getSelected('state', 'OK')?>>Oklahoma</option>
</select>
<?=Form::select('state')->data(['TX' => 'Texas', 'AR' => 'Arkansas', 'OK' => 'Oklahoma'])->label('Choose')?>
<?=Form::select('color')->data(['Red', 'White', 'Blue'], true)->selected('White')?>

Checkboxes and Radios

<input type="checkbox" name="pets" value="Cat" <?=Form::getChecked('pets', 'Cat')?> /> Cat
<input type="checkbox" name="pets" value="Dog" <?=Form::getChecked('pets', 'Dog')?> /> Dog
<input type="checkbox" name="pets" value="Fish" <?=Form::getChecked('pets', 'Fish')?> /> Fish
<input type="radio" name="color" value="Red" <?=Form::getChecked('color', 'Red')?> /> Red
<input type="radio" name="color" value="Blue" <?=Form::getChecked('color', 'Blue')?> /> Blue
<input type="radio" name="color" value="Green" <?=Form::getChecked('color', 'Green')?> /> Green
<?=Form::checkbox('pets')->value('Cat')?> Cat
<?=Form::checkbox('pets')->value('Dog')->checked()?> Dog
<?=Form::checkbox('pets')->value('Fish')?> Fish
<?=Form::radio('color')->value('Red')?> Red
<?=Form::radio('color')->value('Blue')->checked()?> Blue
<?=Form::radio('color')->value('Green')?> Green

Use the checkedWhen() method if you want to check something pending some condition. Pass any condition you like. If it evaluates to true, it will call checked() on the element.

<?=Form::radio('color')->value('Red')->checkedWhen($some_value == 'Red')?> Red
<?=Form::radio('color')->value('Blue')->checkedWhen($some_value == 'Blue')?> Blue
<?=Form::radio('color')->value('Green')->checkedWhen($some_value == 'Green')?> Green

checkedWhen() works for both radios and checkboxes.

Installation

This package is installable and autoloadable via Composer as werx/forms. If you aren't familiar with the Composer Dependency Manager for PHP, you should read this first.

$ composer require werx/forms --prefer-dist

Contributing

Unit Testing

$ composer test

Coding Standards

This library uses PHP_CodeSniffer to ensure coding standards are followed.

I have adopted the PHP FIG PSR-2 Coding Standard EXCEPT for the tabs vs spaces for indentation rule. PSR-2 says 4 spaces. I use tabs. No discussion.

To support indenting with tabs, I've defined a custom PSR-2 ruleset that extends the standard PSR-2 ruleset used by PHP_CodeSniffer. You can find this ruleset in the root of this project at PSR2Tabs.xml

Execute the codesniffer command from the root of this project to run the sniffer using these custom rules and codefixer command to correct them.

$ composer codesniffer
$ composer codefixer

统计信息

  • 总下载量: 5.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固