我在提交表单后尝试保存表单输入,我尝试了这个:
public $username;
public function loginForm() {
$this->login =
"<form action='' method='post'>" .
"<input id=first_name type=text class=validate name=username value=$username>" .
if (isset($_POST["submit"]) && (empty($_POST["username"]))) {
$this->username = $_POST["username"];
它仍然说没有定义变量用户名,我做错了什么?
答案 0 :(得分:0)
通过将var放在函数内来修复:
public function displayLogin() {
$username = isset($_POST['username']) ? $_POST['username'] : '';
答案 1 :(得分:-1)
这里缺少一些引用:
public $username;
public function loginForm() {
$this->login =
'<form action="" method="post">' .
'<input id="first_name" type="text" class="validate" name="username" value="' . $username . '">' .
if (isset($_POST["submit"]) && (empty($_POST["username"]))) {
$this->username = $_POST["username"];