我有一个付款的PHP表单,如下所示:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<h2>Payment Gateway Testing Sample</h2>
<h3>Fill the form and submit it for starting the transaction...</h3>
</div>
<div>
<table>
<form name="postForm" action="form_process.php" method="POST" >
<tr><td><input type="hidden" name="txnid" value="<?php echo $txnid=time().rand(1000,99999); ?>" /></td></tr>
<tr><td>amount</td><td><input type="text" name="amount" value="" /></td></tr>
<tr><td>firstname</td><td><input type="text" name="firstname" value="" /></td></tr>
<tr><td>email</td><td><input type="text" name="email" value="" /></td></tr>
<tr><td>phone</td><td><input type="text" name="phone" value="" /></td></tr>
<tr><td>productinfo</td><td><input type="text" name="productinfo" value="" /></td></tr>
<tr><td><input type="hidden" name="surl" value="success.php" size="64" /></td></tr>
<tr><td><input type="hidden" name="furl" value="fail.php" size="64" /></td></tr>
<tr><td><input type="submit" /></td><td><input type="reset" /></td></tr>
</form>
</table>
</div>
</body>
</html>
&#13;
当用户登录并访问此页面时,应使用会话自动将数据添加到表单中。我怎么能这样做?
答案 0 :(得分:1)
以下答案适用于PHP Session。我们可以使用$ _SESSION访问所有Session值。链接PHP: $_SESSION - Manual 。但首先你需要在$ _SESSION(会话)中存储数据。
<?php session_start();?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<h2>Payment Gateway Testing Sample</h2>
<h3>Fill the form and submit it for starting the transaction...</h3>
</div>
<div>
<table>
<form name="postForm" action="form_process.php" method="POST" >
<tr><td><input type="hidden" name="txnid" value="<?php echo $txnid=time().rand(1000,99999); ?>" /></td></tr>
<tr><td>amount</td><td><input type="text" name="amount" value="<?php echo $_SESSION['amount']; ?>" /></td></tr>
<tr><td>firstname</td><td><input type="text" name="firstname" value="<?php echo $_SESSION['firstname']; ?>" /></td></tr>
<tr><td>email</td><td><input type="text" name="email" value="<?php echo $_SESSION['email']; ?>" /></td></tr>
<tr><td>phone</td><td><input type="text" name="phone" value="<?php echo $_SESSION['phone']; ?>" /></td></tr>
<tr><td>productinfo</td><td><input type="text" name="productinfo" value="<?php echo $_SESSION['productinfo']; ?>" /></td></tr>
<tr><td><input type="hidden" name="surl" value="success.php" size="64" /></td></tr>
<tr><td><input type="hidden" name="furl" value="fail.php" size="64" /></td></tr>
<tr><td><input type="submit" /></td><td><input type="reset" /></td></tr>
</form>
</table>
</div>
</body>
</html>