2017-02-15 119 views
0

我有兩個php頁面:info.phpthankyou.php如何將數據從PHP中的表單傳遞到另一個PHP的HTML

info.php,我有一個表格是這樣的:

<span class="help" style="padding-left:4%;">&Nu;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 

我覺得是有什麼錯我上面的代碼。 。 。任何人都可以告訴我如何解決它?

+1

基於Web的表單通常需要FORM標籤...我不相信您可以將FORM標籤參數分配給SPAN標籤,並使其表現形式類似於FORM標籤...請參閱https://www.w3schools.com /php/php_forms.asp –

回答

1

在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; ?> 
相關問題