簡體   English   中英

如何在PHP重定向頁面中顯示下拉列表和復選框選擇的值以進行確認?

[英]How to display the dropdown & checkbox selected value in redirected page for confirmation IN PHP?

<form action="action.php" method="POST"  target="_self">
<table class="main"  border="1"  height="100%" align="center">
<h3>
<p id="id1" style="background-color: #9FF" >Registration form</p></h3>

 <tr><td> First Name:<span style="color:red">*</span> </td> 
<td> <input type="text"  name="fname" value="" placeholder="firstname"    required="required" maxlength="25"></td></tr>
 <tr><td> SurName:<span style="color:red">*</span></td> 
 <td><input type="text"  name="sname" value=""  placeholder="lastname" required="required" maxlength="20"/> </td></tr>
 <tr><td>Age:<span style="color:red">*</span></td>
 <td> <input type="text" name="age" value="" required/></td></tr>
 <tr><td>Date of Birth:<span style="color:red">*</span></td>
 <td><input type="date" name="DOB" value="" required/></td></tr>
 <tr><td> Gender:<span style="color:red">*</span></td>
  <td><input type="radio" name="gender" value="male" required/>Male 
   <input type="radio" name="gender" value="Female" />Female</td></tr>
  <tr><td>Qualification:<span style="color:red">*</span></td>
   <td> <select name="study" required>
   <option value="">---Select---</option>
  <option value="btech">B.Tech</option>
  <option value="BSc">BSc</option>
  <option value="BCom">BCom</option>
 </select></td></tr>
  <tr><td> State:<span style="color:red">*</span></td>
<td><Select name="state" required >
<option value="">---Select---</option>
<option valuie="AndhraPradesh">AndhraPradesh</option>
<option value="Telangana">Telangana</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="Kerala">Kerala</option>
<option vgalue="Maharastra">Maharastra</option>
</Select></td></tr> 

<tr><td>Profile:<span style="color:red">*</span></td><td><input type="checkbox" name="profile" value="Java" />Java
                            <input type="checkbox" name="profile" value="PHP" />PHP
                            <input type="checkbox" name="profile" val

    ue="Android" />Android</td> </tr>
    <tr><td> Address for Communication:</td><td><textarea name="adr" rows="5" cols="30" ></textarea></td></tr>
            <tr><td colspan="2" align="center"><input type="submit" value="submit" /></td></tr>                  
    </table></form>

**這是我的注冊表,現在我想在下一頁(即在action.php中)顯示所有選定的值,其代碼如下********

    <form action="store.php" method="post" align="center" target="_self">
    <label>Name of the person:</label> 
   <input type="hidden" name="person" value="<?= $_POST['fname'];?>"></input><?=$_POST['fname'];?>  <br />
    <label>Name of the Surname:</label>
    <input type="hidden" name="surname" value="<?= $_POST['sname'];?>"></input><?=$_POST['sname'];?>  <br />
    <label>His Age:</label>
     <input type="hidden" name="age" value="<?= $_POST['age'];?>"></input><?=$_POST['age'];?> <br />
     <label>Date of Birth:</label>
     <input type="hidden" name="dob" value="<$_POST['DOB'];?>"></input><?=$_POST['DOB'];?>  <br />
      <label>Gender:</label> 
     <input type="hidden" name="gender" value="<?= $_POST['gender'];?>"></input><?=$_POST['gender'];?> <br />
      <label>Education:</label> 
     <input type="hidden" name="edu" value="<?php if(isset($_POST['submit']))echo $_POST['study']?>"></input><?php if(isset($_POST['submit'])) echo $_POST['study']?>;?> 
      <br />
      <label>State:</label>
      <input type="hidden" name="state" value="<?if(isset($_POST['submit']))echo $_POST['state']?>"></input><?php if(isset($_POST['submit'])) echo $_POST['state']?>;?> 
      <br />
      <label>Good At:</label>
     <input type="hidden" name="profile" value="<?= $_POST['profile'];?>"></input><?=$_POST['profile'];?>  <br />
      <label>Address:</label>
      <input type="hidden" name="adr" value="<?= $_POST['adr'];?>"></input><?=$_POST['adr'];?>  <br /><br /><br />
      <input type="submit" value="confirm" name="submit"></input>

****該下拉列表沒有顯示,還建議如果單擊“確定”后必須將已確認的值存儲在數據庫中。為此,我應該從action.php或注冊中輸入的隱藏字段的名稱中獲取這些值輸入字段名稱?

  1. 您的代碼中有很多語法錯誤。
  2. 您尚未在“提交”按鈕中添加名稱屬性。 其中應為name =“ submit” 否則,在顯示下拉值時,它將被檢查到您的代碼中,並且不會顯示(因為在$ _POST數組中未找到名為Submit的變量)。
  3. 該復選框使用相同的名稱。 因此它應該是一個數組。 使用name = profile []代替name = profile

最終form.php應該看起來像這樣:

<form action="action.php" method="POST"  target="_self">
<table class="main"  border="1"  height="100%" align="center">
<h3>
<p id="id1" style="background-color: #9FF" >Registration form</p></h3>

 <tr><td> First Name:<span style="color:red">*</span> </td> 
<td> <input type="text"  name="fname" value="" placeholder="firstname"    required="required" maxlength="25"></td></tr>
 <tr><td> SurName:<span style="color:red">*</span></td> 
 <td><input type="text"  name="sname" value=""  placeholder="lastname" required="required" maxlength="20"/> </td></tr>
 <tr><td>Age:<span style="color:red">*</span></td>
 <td> <input type="text" name="age" value="" required/></td></tr>
 <tr><td>Date of Birth:<span style="color:red">*</span></td>
 <td><input type="date" name="DOB" value="" required/></td></tr>
 <tr><td> Gender:<span style="color:red">*</span></td>
  <td><input type="radio" name="gender" value="male" required/>Male 
   <input type="radio" name="gender" value="Female" />Female</td></tr>
  <tr><td>Qualification:<span style="color:red">*</span></td>
   <td> <select name="study" required>
   <option value="">---Select---</option>
  <option value="btech">B.Tech</option>
  <option value="BSc">BSc</option>
  <option value="BCom">BCom</option>
 </select></td></tr>
  <tr><td> State:<span style="color:red">*</span></td>
<td><Select name="state" required >
<option value="">---Select---</option>
<option value="AndhraPradesh">AndhraPradesh</option>
<option value="Telangana">Telangana</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="Kerala">Kerala</option>
<option vgalue="Maharastra">Maharastra</option>
</Select></td></tr> 

<tr><td>Profile:<span style="color:red">*</span></td><td>

                <input type="checkbox" name="profile[]" value="Java" />Java
                            <input type="checkbox" name="profile[]" value="PHP" />PHP
                            <input type="checkbox" name="profile[]" value="Android" />Android</td> </tr>
    <tr><td> Address for Communication:</td><td><textarea name="adr" rows="5" cols="30" ></textarea></td></tr>
            <tr><td colspan="2" align="center"><input type="submit" name="submit" value="submit" /></td></tr>                  
    </table></form>

而且action.php應該是這樣的:

<form action="store.php" method="post" align="center" target="_self">
    <label>Name of the person:</label> 
   <input type="hidden" name="person" value="<?= $_POST['fname'];?>"></input><?=$_POST['fname'];?>  <br />
    <label>Name of the Surname:</label>
    <input type="hidden" name="surname" value="<?= $_POST['sname'];?>"></input><?=$_POST['sname'];?>  <br />
    <label>His Age:</label>
     <input type="hidden" name="age" value="<?= $_POST['age'];?>"></input><?=$_POST['age'];?> <br />
     <label>Date of Birth:</label>
     <input type="hidden" name="dob" value="<$_POST['DOB'];?>"></input><?=$_POST['DOB'];?>  <br />
      <label>Gender:</label> 
     <input type="hidden" name="gender" value="<?= $_POST['gender'];?>"></input><?=$_POST['gender'];?> <br />
      <label>Education:</label> 
     <input type="hidden" name="edu" value="<?php if(isset($_POST['submit'])) echo $_POST['study'];?>"></input><?php if(isset($_POST['submit'])) echo $_POST['study'];?> 
      <br />
      <label>State:</label>
      <input type="hidden" name="state" value="<?if(isset($_POST['submit'])) echo $_POST['state'];?>"></input><?php if(isset($_POST['submit'])) echo $_POST['state'];?> 
      <br />
      <label>Good At:</label>
     <input type="hidden" name="profile" value="<?php echo implode(", ", $_POST['profile']); ?>">
<?php 
echo implode(", ", $_POST['profile']);
//print_r($_POST['profile']);
 ?>  

<br />
      <label>Address:</label>
      <input type="hidden" name="adr" value="<?= $_POST['adr'];?>"></input><?=$_POST['adr'];?>  <br /><br /><br />
      <input type="submit" value="confirm" name="submit"></input>

您將要存儲在數據庫中的數據取決於您的數據庫設計。

例如:-這取決於您是將復選框值存儲為逗號分隔的字符串,還是使用其他表存儲。

一旦進入了action.php頁面,程序在這一點上的任何操作都可以使用會話將使用注冊表單獲取的數據發送到store.php。 否則,如果使用$ _POST在store.php中,您將獲得在action.php頁面的那些隱藏輸入字段中的輸入值。

我更改了一些代碼...您有一些小語法錯誤...

 <form action="store.php" method="post" align="center" target="_self">
    <label>Name of the person:</label> 
   <input type="hidden" name="person" value="<?= $_POST['fname'];?>"></input><?=$_POST['fname'];?>  <br />
    <label>Name of the Surname:</label>
    <input type="hidden" name="surname" value="<?= $_POST['sname'];?>"></input><?=$_POST['sname'];?>  <br />
    <label>His Age:</label>
     <input type="hidden" name="age" value="<?= $_POST['age'];?>"></input><?=$_POST['age'];?> <br />
     <label>Date of Birth:</label>
     <input type="hidden" name="dob" value="<$_POST['DOB'];?>"></input><?=$_POST['DOB'];?>  <br />
      <label>Gender:</label> 
     <input type="hidden" name="gender" value="<?= $_POST['gender'];?>"></input><?=$_POST['gender'];?> <br />
      <label>Education:</label> 
     <input type="hidden" name="edu" value="<?php echo $_POST['study']; ?>"></input><?php echo $_POST['study'];?> 
      <br />
      <label>State:</label>
      <input type="hidden" name="state" value="<?php echo $_POST['state'];?>"></input><?php  echo $_POST['state'];?> 
      <br />
      <label>Good At:</label>
     <input type="hidden" name="profile" value="<?= $_POST['profile'];?>"></input><?=$_POST['profile'];?>  <br />
      <label>Address:</label>
      <input type="hidden" name="adr" value="<?= $_POST['adr'];?>"></input><?=$_POST['adr'];?>  <br /><br /><br />
      <input type="submit" value="confirm" name="submit"></input>
    <SELECT name="abc">
<option value="option1" selected> This is option 1 </option>
<option value="option2"> This is option 2 </option>
</SELECT>

和php在提交帖子時獲得$_POST['abc']option1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM