【发布时间】:2019-08-10 23:58:51
【问题描述】:
我正在尝试使用 Bootstrap 的模态组件从中获取一些信息并将它们保存到会话中。
我希望人们将他们的名字、姓氏和电子邮件地址输入该表单,当他们单击提交时,这些信息会保存到会话中,以便我可以在其他页面上使用它们。此外,当他们点击按钮时,他们会被发送到 Paypal 的网站,付款后,他们会被发送回我的网站,我应该在其中显示他们的信息。问题是:我无法获取信息。
这是我第一次在 PHP 中使用 Session 函数,并且我设法保存了一个变量并将它从一个页面使用到另一个页面。另外,我成功地存储了表单中的数据并使用了它。但是当我将该表单放入模态框时,我在网站上出现了错误。
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Entrez vos informations</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body d-flex justify-content-center">
<form name="identifiants" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<p>Nom :
<input type="text" name="nom" size="20" required /></p>
<p>Prénom :
<input type="text" name="prenom" size="20" required /></p>
<p>Adresse email :
<input type="email" name="email" size="20" required /></p>
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="WNNJPMXAANNPY">
<input class="btn btn-outline-warning" type="submit" name="Submit" value="Submit!" />
<?php if (isset($_POST['Submit'])) {
$_SESSION['nom'] = $_POST['nom'];
$_SESSION['prenom'] = $_POST['prenom'];
$_SESSION['email'] = $_POST['email'];
}
?>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
这是我其他页面的代码:
echo $_SESSION['logiciel'];
echo $_SESSION['nom'];
echo $_SESSION['prenom'];
echo $_SESSION['email'];
?>
我确实放了一个 session_start();在我所有页面的开头,它仍然不起作用。 我试图将第一页的 php 部分从表单、div 和模态中取出,但没有任何效果。然而,我仍然在另一页上显示“logiciel”变量,因为我在代码中较早地保存了它。
【问题讨论】:
-
您应该在页面顶部添加
session_start(),并检查它是否在此之后立即发布任何数据。
标签: php html session modal-dialog