在php中维护html控件状态?

发布于 2024-12-14 00:16:34 字数 352 浏览 4 评论 0原文

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

例如,我有这样的:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如歌彻婉言 2024-12-21 00:16:34

您可以创建一个助手来操作 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文