tomdabrain/formhandler

10行代码内的交互式表单

v3.3.8 2015-12-17 11:47 UTC

This package is auto-updated.

Last update: 2024-09-06 00:23:20 UTC


README

GitHub license Build Status php 7.4.x

FormHandler 是一个用 PHP 编写的 "模块",它允许你以简单的方式创建动态表单。简单到你可以用10行代码构建一个完整的表单,包括字段验证!

安装

使用以下命令安装最新版本:

$ composer require formhandler/formhandler

当供应商目录位于您的 Web 应用程序根目录之外时,请使用 FHTML 目录上的符号链接使其公开可用。

例如:将 vendor/formhandler/formhandler/src/FHTML 映射到您的网站根目录的 /FHTML/。然后添加到您的应用程序

<?php

fh_conf('FH_FHTML_DIR', '/FHTML/');

基本用法

<?php

//include the class (only needed when not using Composer)
include "FH3/class.FormHandler.php";

//when using composer include the autoloader of composer
require __DIR__ . '/vendor/autoload.php';

//create a new FormHandler object
$form = new FormHandler();

//some fields.. (see manual for examples)
$form->textField("Name", "name", FH_STRING, 20, 40);
$form->textField("Age", "age", FH_INTEGER, 4, 2);

//button for submitting
$form->submitButton();

//set the 'commit-after-form' function
$form->onCorrect('doRun');

//display the form
$form->flush();

//the 'commit-after-form' function
function doRun($data)
{
    echo "Hello ". $data['name'].", you are ".$data['age'] ." years old!";
}

文档

有关文档的扩展版本,请查阅位于 http://www.fh3.nl/manual/manual.html 的手册

许可证

FormHandler 根据 GNU Lesser General Public License 版本 2.1 许可 - 有关详细信息,请参阅 LICENSE 文件