我在我的網站上獲得了註冊/登錄系統,現在它顯示頁面頂部的錯誤和成功文本。我希望它在窗體下顯示它。但是,無論何時我嘗試將其添加到表單下方,它都不起作用!提交表單無法正常工作時顯示錯誤/成功
session_start();
include_once('class.register.php');
$register = new Register();
if(isset($_POST['register']))
{
if($register->process())
echo "Successfully Signed Up!";
else
$register->show_errors();
}
$token = $_SESSION['token'] = md5(uniqid(mt_rand(),true));
這可以工作,但它會將文本輸出到頁面頂部。
我試圖把「形式」結束標籤下面這段代碼:
<?php
if(isset($_POST['register']))
{
if($register->process())
echo "Successfully Signed Up!";
else
$register->show_errors();
}
?>
但是當我移動下來形式下,然後它說「無效提交」,這是由這個原因引起:
public function valid_token()
{
if(!isset($_SESSION['token']) || $this->token != $_SESSION['token'])
$this->errors[] = 'Invalid Submission';
return count($this->errors)? 0 : 1;
}
我這是因此,談到
<form role="form" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<label for="firstname">Firstname</label>
<input type="text" class="form-control" id="firstname" name="firstname" placeholder="Firstname">
</div>
<div class="col-sm-6">
<label for="surname">Surname</label>
<input type="text" class="form-control" id="surname" name="surname" placeholder="Surname">
</div>
</div>
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="ruser" name="ruser" placeholder="Username">
</div>
<div class="form-group">
<label for="email2">Email address</label>
<input type="email" class="form-control" id="remail" name="remail" placeholder="Enter email">
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<label for="password2">Password</label>
<input type="password" class="form-control" id="rpass" name="rpass" placeholder="Password">
</div>
<div class="col-sm-6">
<label for="password2">Repeat password</label>
<input type="password" class="form-control" id="rpass2" name="rpass2" placeholder="Password">
</div>
</div>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> I agree to the <a href="#">Terms of Service</a> and <a href="#">Privacy Policy</a>
</label>
</div>
<input type="hidden" name="token" value="<?php echo $token;?>"/>
<button type="submit" name="register" class="btn btn-block btn-color btn-xxl">Create an account</button>
</form>
表格,表格是什麼? –
您輸入信息的html屬性表單。
- 這種形式:P – Anders