如何通过PHP设置文本框的值? [英] How can I set the value of a textbox through PHP?

查看:726
本文介绍了如何通过PHP设置文本框的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在registrationg页面中有这个空的文本框.用户输入一些数据,点击继续,然后出现一个确认页面.如果数据不正确,则用户点击返回可更正错误.但是,当他返回时,所有文本框都是空的.因此,我想到的第一件事是将用户数据存储在会话中(我有一个User类,该类保存所有这些数据,因此我将此类存储在会话中).当用户返回时,我可以检索数据.

So I have this empty textboxes in a registrationg page. The user enters some data, hits continue and then there's a confirmation page. If the data is incorrect, the user hits go back to go correct whatever was wrong. However, when he goes back, all the textboxes are empty. So the first thing that comes to my mind is to store the user data in a Session (I have a User class that holds all this data so I store the class in the session). When the user goes back I am able to retrieve the data.

我做这样的事情:

if($_SESSION['UserInfo'])
{
    $user = $_SESSION['UserInfo'];

    $firstName = $user->FirstName;
    $lastName = $user->LastName;
}

如何将这些变量放在文本框中?

How would I put these variables in a textbox?

推荐答案

要设置该值,您可以回显value属性内的内容:

To set the value, you can just echo out the content inside the value attribute:

<input type="text" name="firstname" value="<?php echo htmlentities($firstName); ?>" />
<input type="text" name="lastname" value="<?php echo htmlentities($lastName); ?>" />

这篇关于如何通过PHP设置文本框的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆