基于從“串列頁面”使用的“串列”(URL)鏈接......我需要能夠使用該特定資料預先填充“表單頁面”上的“selectedListing”欄位。
我已經為“formHandler”頁面提供了一個有效的 php 代碼。
我確信我還需要在這兩個頁面之間使用一些 PHP,我只是不知道該怎么做。
串列頁面
<!DOCTYPE html>
<head>
<title>Listing Page</title>
<style>
.theListings {
margin: auto;
text-align: center;
}
</style>
</head>
<body>
<div class="theListings">
<h1>The Listings</h1>
<a>To get a quote, please select the listing you are interested from the list below:</a>
<br>
<br>
<a href="userForm.php" value="Listing A">Listing A</a>
<br>
<br>
<a href="userForm.php" value="Listing B">Listing B</a>
<br>
<br>
<a href="userForm.com" value="Listing C">Listing C</a>
</div>
</body>
</html>
表單頁面
<!DOCTYPE html>
<head>
<title>Form Page</title>
<style>
.formContainer {
margin: auto;
text-align: center;
}
</style>
</head>
<body>
<div class="formContainer">
<h1>The Form</h1>
<a>To complete your quote, please fill out and submit the form below.</a><br><br>
<form action="/formHandler.php" method="post" enctype="multipart/form-data">
<input type="text" class="selectedListing" name="selectListing" placeholder="Selected
Listing"><br><br>
<input type="text" name="userName" placeholder="Full Name"><br><br>
<input type="email" name="userEmail" placeholder="Email Address"><br><br>
<input type="tel" name="userPhone" placeholder="Phone Number"><br><br>
<input type="submit" name="submitButton" value="Submit Form">
</form>
</div>
</body>
</html>
uj5u.com熱心網友回復:
a, https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a上沒有 value 屬性。您可以將該值作為 URL 上的 GET 引數傳遞。改變:
<a href="userForm.php" value="Listing A">
至:
<a href="userForm.php?listing=A">
然后userForm.php使用:
$_GET['listing']
讀取值。
如果input假設具有您可以執行的值:
<input type="text" class="selectedListing" name="selectListing" placeholder="Selected
Listing" value="<?php echo (!empty($_GET['listing']) && in_array($_GET['listing'], array('A', 'B', 'C')) ? $_GET['listing'] : ''); ?>">
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/482985.html
