如何将数据从PHP中的表单传递到另一个PHP的HTML
问题描述:
我有两个php页面:info.php
和thankyou.php
。如何将数据从PHP中的表单传递到另一个PHP的HTML
在info.php
,我有一个表格是这样的:
<span class="help" style="padding-left:4%;">Νame as it appears on ID Card.</span>
<label for="id_holder">ID Name :</label>
<span action="../myaccount/Luhusian/thankyou.php" method="post" id="id_holder">
<input type="text" autocomplete="off" class="large" pattern=".{2,30}" maxlength="32" name="id_holder" value="" required="" title="ID fullname">
</span>
我想在thankyou.php
使用表单数据。 。 。例如,全名,如下图所示:
<div class="span8" id="js_activityCollection">
<section class="activityModule shadow none" aria-labelledby="activityModuleHeaderNone">
<h1 style="font-size: 18px;font-weight: bold; border-bottom: 1px solid #EEE; height:40px;">
Thank you <?php echo $_POST["id_holder"]; ?>
</h1>
</section>
</div>
但是当我尝试运行它,我得到这个错误:
Thank you,
Notice: Undefined index: id_holder in C:\xampp\htdocs\thankyou.php on line 14
我觉得是有什么错我上面的代码。 。 。任何人都可以告诉我如何解决它?
答
在info.php的文件,你应该使用,而不是跨
<form action="../myaccount/Luhusian/thankyou.php" method="post" id="id_holder">
<input type="text" autocomplete="off" class="large" pattern=".{2,30}" maxlength="32" name="id_holder" value="" required="" title="ID fullname">
</form>
但形式是块元素的形式,我想这就是为什么你要使用范围。你可以通过简单地增加一个内联CSS使 它内联元素(但我不推荐使用内联CSS)
<form style="display:inline-block" action="../myaccount/Luhusian/thankyou.php" method="post" id="id_holder">
<input type="text" autocomplete="off" class="large" pattern=".{2,30}" maxlength="32" name="id_holder" value="" required="" title="ID fullname">
</form>
然后在您的感谢您网页,首先检查是否字段是isset然后渲染页面
<?php if (isset($_POST['id_holder'])) : ?>
<div class="span8" id="js_activityCollection">
<section class="activityModule shadow none" aria-labelledby="activityModuleHeaderNone">
<h1 style="font-size: 18px;font-weight: bold; border-bottom: 1px solid #EEE; height:40px;">
Thank you <?php echo $_POST["id_holder"]; ?>
</h1>
</section>
</div>
<?php else : ?>
<p>Please fill in the form correctly</p>
<?php endif; ?>
基于Web的表单通常需要FORM标签...我不相信您可以将FORM标签参数分配给SPAN标签,并使其表现形式类似于FORM标签...请参阅https://www.w3schools.com /php/php_forms.asp –