在php中维护html控件状态?
当用户注册失败时,字段会消失,因为有一个回发到服务器。
例如,我有这样的:
<input name="email" type="text" id="email1"/>
如果用户登录失败,会发生什么字段会消失。我可以做到这一点。
<input name="email" type="text" id="email1" value="<?php echo isset($_post["email"])?$_post["email"]:""; ?>"/>
但路途有点遥远,有没有更简单的方法来维持状态呢?
When a user fails to register, the fields disappear cause there is a postback to the server..
So for example, I have this:
<input name="email" type="text" id="email1"/>
If the user fails to login, what will happen is that the fields will disappear. I could do this.
<input name="email" type="text" id="email1" value="<?php echo isset($_post["email"])?$_post["email"]:""; ?>"/>
But it is a bit a long way, is there an easier way to maintain a state?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个助手来操作 HTML 表单标签。您可以在网上找到许多库,或者自己制作一个。
大多数 MVC 框架都有这样的功能(Cakephp、codeigniter),但也有独立的功能。
示例/文档:
codeigniter:
http://codeigniter.com/user_guide/helpers/form_helper.html
cakephp:
http://api.cakephp.org/class/form-helper
注意:
http://akelos.org/wiki/forms
You could make one helper to manipulate HTML form tags. There are many libraries that you can find in web, or just made one.
Most MVC frameworks have features like this (Cakephp,codeigniter), but theres standalones too.
Samples/Doc:
codeigniter:
http://codeigniter.com/user_guide/helpers/form_helper.html
cakephp:
http://api.cakephp.org/class/form-helper
akelos:
http://akelos.org/wiki/forms