【问题标题】:Maintaining html control state in php?在php中维护html控件状态?
【发布时间】:2011-11-05 14:19:56
【问题描述】:

当用户注册失败时,字段消失,因为有一个回发到服务器..

例如,我有这个:

<input name="email" type="text"  id="email1"/>

如果用户登录失败,那么字段将会消失。我可以这样做。

<input name="email" type="text"  id="email1" value="<?php echo isset($_post["email"])?$_post["email"]:""; ?>"/>

但是路途有点远,有没有更简单的保持状态的方法?

【问题讨论】:

  • 并非如此,因为您的脚本会提供一个空白表单,而浏览器会显示它。但是,如果您使用表单库,它们通常带有这样的功能。这样可能对你来说会更容易。

标签: php html postback


【解决方案1】:

您可以创建一个助手来操作 HTML 表单标签。您可以在网络上找到许多库,或者只是制作了一个。

大多数 MVC 框架都有这样的功能(Cakephp、codeigniter),但也有独立的。

样品/文件:

代码点火器: http://codeigniter.com/user_guide/helpers/form_helper.html

蛋糕PHP: http://api.cakephp.org/class/form-helper

阿克洛斯: http://akelos.org/wiki/forms

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 2012-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多