single / formrestore
一组实现从保存的 JSON 数据中填充表单的类
1.0.0
2014-03-28 07:33 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-15 00:13:55 UTC
README
Solo 框架的组件,提供从保存的数据恢复 HTML 表单状态的功能。
有时在服务器上验证表单数据后,某些字段可能填写不正确(无效),需要显示用户之前输入的值。
FormRestore 类与 Smarty 插件一起可以解决这个问题。
要求
jQuery
安装
通过 composer 安装
"require": {
"solo/formrestore": "dev-master"
}
示例
HTML 代码
<html>
<script language="javascript" type="text/javascript" src="jquery.js" />
<?php
echo FormRestore::restore();
?>
<form id='my_form_id'>
<input type='text' name='age' />
<input type="checkbox" name="value" value="42"/>
<input type="submit" value="check!"/>
</form>
</html>
服务器端代码
<?php
$age = $_POST['age'];
if (!is_int($age))
{
FormRestore::saveData("my_form_id");
// redirect to previous page here!
}
?>