我的網站上有一張銷售表格,要求用戶輸入幾條關于他們自己的資訊。
然而,許多網站訪問者要么被表格嚇倒,要么認為它“太長”。
為了嘗試使表單程序更有趣、更有吸引力和“用戶友好”,我想嘗試將表單分散到多個頁面上,每個頁面上都有創造性的語言,以幫助用戶更輕松地分享他們的在提交表格之前一次一點的資訊。
我為這個例子大幅縮減了表格。我特別迷失的是如何將資料從一個“表單頁”傳輸到下一個,因為資訊會堆積到最后的“提交”頁。
我希望它的功能就像一個分布在幾頁上的表單。
任何指導或建議將不勝感激。
表格第 1 頁
<html>
<head>
<title>Form Page 1</title>
</head>
<body>
<form action="formpage2.php" method="POST">
<input type="text" id="userName" name="userName" placeholder="Enter Your Name.." required/>
<input type="submit" value="Continue">
</form>
</body>
</html>
表格第 2 頁
<html>
<head>
<title>Form Page 2</title>
</head>
<body>
<form action="formpage3.php" method="POST">
<!-- Data Stack from previous formpage(s)-->
<?php
$name = $_POST['userName'];
?>
<select id="userAge" name="userAge" class="ageField">
<option value="0" selected="selected" disabled="disabled">Age</option>
<option value="Under 18">Under 18</option>
<option value="18-25">18-25</option>
<option value="26-35">26-35</option>
<option value="36-45">36-45</option>
<option value="46-55">46-55</option>
<option value="56-65">56-65</option>
<option value="66 ">66 </option>
</select>
<input type="submit" value="Continue">
</form>
</body>
</html>
表格第 3 頁
<html>
<head>
<title>Form Page 3</title>
</head>
<body>
<form action="formpage4.php" method="POST">
<!-- Data Stack from previous formpage(s)-->
<?php
$name = $_POST['userName'];
$age = $_POST['userAge'];
?>
<textarea id="userMessage" name="userMessage" placeholder="Type message here..."></textarea>
<input type="submit" value="Continue">
</form>
</body>
</html>
表格第 4 頁
<html>
<head>
<title>Form Page 4</title>
</head>
<body>
<form action="formpage5.php" method="POST">
<!-- Data Stack from previous formpage(s)-->
<?php
$name = $_POST['userName'];
$age = $_POST['userAge'];
$message = $_POST['userMessage']
?>
<input type="checkbox" id="terms" name="terms" value="Agreed">
<input type="submit" value="Submit Form">
</form>
</body>
</html>
表格第 5 頁
<?php
$name = $_POST['userName'];
$age = $_POST['userAge'];
$message = $_POST['userMessage'];
$termsAgreed = $_POST['terms'];
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
$composition =
"\r\n\n\nName: " . $name .
"\r\nAge: " . $age .
"\r\n\nAgreed To Terms & Conditions?: " . $termsAgreed .
"\r\n\n\nMessage: " . $message;
/* I left out the bottom of this final handling page,
because it isn't relevant to my particular issue */
?>
uj5u.com熱心網友回復:
我會說你已經在正確的道路上。我認為您可以在代碼中使用隱藏的表單欄位,它應該很容易讓您理解。
假設你有 page1.php
<html>
<head>
<title>Form Page 1</title>
</head>
<body>
<form action="page2.php" method="POST">
<input type="text" id="userName" name="userName" placeholder="Enter Your Name.." required/>
<input type="submit" value="Continue">
</form>
</body>
</html>
然后在 page2.php
<html>
<head>
<title>Form Page 1</title>
</head>
<body>
<form action="page3.php" method="POST">
<input type="hidden" name="userName" value="<?php echo $_POST['userName']; ?>" /> <!-- <-- the hidden field -->
<select id="userAge" name="userAge" class="ageField">
<option value="0" selected="selected" disabled="disabled">Age</option>
<option value="Under 18">Under 18</option>
<option value="18-25">18-25</option>
<option value="26-35">26-35</option>
<option value="36-45">36-45</option>
<option value="46-55">46-55</option>
<option value="56-65">56-65</option>
<option value="66 ">66 </option>
</select>
<input type="submit" value="Continue">
</form>
</body>
</html>
它在下一頁繼續相同,您將前一個表單放入具有相同名稱的隱藏欄位中,然后當您在最后一頁提交時,就像您在最后階段提交所有表單值并且您的 php 代碼能夠從 $_POST[] 陣列中獲取所有值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/498203.html
標籤:javascript php 形式 邮政 得到
上一篇:phpformpost更新資料庫并重繪頁面但重繪后不更新頁面上的資料
下一篇:除非選中框,否則禁用“提交”按鈕
