Reputation: 21
I have a php web form like this. The drop down menu is populated from a SQL database with php but I'm just showing it in HTML for simplicity...
<form action ="confirm.php" method="post">
Name <input type="text" id="name" value=" "><br>
City <input type="text" id="city" value=" "><br>
Telephone <input type="text" id="telephone" value=" "><br>
Street Address <input type="text" id="st_address" value=" "><br>
Zip Code <input type="text" id="zip" value=" "><br>
Email <input type="text" id="email" value=" "><br>
<!-- Item 1 -->
Item 1
<select id ="item1" class ="item">
<option value"">Please Select</option>
<option value"">---Appetizers---</option>
<option value="3.25">Spring Roll (2) - $3.25</option>
<option value="6.95">Deep Fried Tofu with Salt & Chili (Hot) - $6.95</option>
<option value="6.95">Deep Fried Wonton - $6.95</option>
<option value"">---Main Courses---</option>
<option value="13.75">Deep Fried Cod Fillet with Ginger Sauce - $13.75</option>
<option value="13.75">Deep Fried Cod Fillet in Sweet & Sour Sauce - $13.75</option>
<option value="11.75">Peppery Chicken (Hot) - $11.75</option>
<option value="11.75">Satay Chicken - $11.75</option>
<option value"">---Lunch Specials---</option>
<option value="8.95">Mixed Vegetable with Chicken - $8.95</option>
<option value="8.95">Braised Fried Bean Curd Vegetables - $8.95</option>
<option value="8.95">Black Bean Sauce Chicken - $8.95</option>
</select>
<br>
</form>
<input type=button onClick="location.href='confirm.php'" value="Proceed to checkout">
I got it to display the filled out/selected information on the same page using JavaScript:
<script>
function getContact() {
// contact information
var name = document.getElementById("name").value;
var city = document.getElementById("city").value;
var telephone = document.getElementById("telephone").value;
var st_address = document.getElementById("st_address").value;
var zip = document.getElementById("zip").value;
var email = document.getElementById("email").value;
document.getElementById("c_name").innerHTML = "Name: " + name;
document.getElementById("c_city").innerHTML = "City: " + city;
document.getElementById("c_telephone").innerHTML = "Telephone: " + telephone;
document.getElementById("c_st_address").innerHTML = "Street Address: " + st_address;
document.getElementById("c_zip").innerHTML = "Zip Code: " + zip;
document.getElementById("c_email").innerHTML = "Email: " + email;
}
var items = document.getElementsByClassName("item");
var output = document.getElementById("output");
function getItems() {
output.innerHTML = "";
for (var i = 0; i < items.length; i++) {
if (items[i].value > 0) {
var sel = items[i].options[items[i].selectedIndex].text;
output.innerHTML += sel + "<br>";
}
}
}
for (var i = 0; i < items.length; i++) {
items[i].addEventListener('change',getItems);
}
</script>
But I would like the information displayed on the confirmation page. How do I link the php page to the confirmation page? Once the two pages are linked, will I be able to reference the web form id's on the confirmation page?
Upvotes: 2
Views: 2579
Reputation: 375
ON your confirmation page use this
<p>Name: <?php echo $_POST['name']?></p>
<p>City: <?php echo $_POST['city']?></p>
<p>Zip: <?php echo $_POST['zip']?></p>
.....
.......
Upvotes: 0
Reputation: 2105
There are 2 ways to deal with the problem:
POST Read more on this http://php.net/manual/en/reserved.variables.post.php With this you need to write form action as your confirmation page. When you hit submit button the data will get transferred to your confirmation page and you can display them there. Access it with $_POST
Session. Read more on this http://php.net/manual/en/book.session.php With this you need to start the session on the form page. The same session will be available on the confirmation page. Access it with $_SESSION.
Upvotes: 1
Reputation:
You are sending POST request with all data to your confirmation page. You can show them UP This way: $name = $_POST['name']; Same with rest of the vields. And then Just echo $name
Upvotes: 0
Reputation: 138277
On your confirm.php do:
<?php echo $_POST["name"];?>
This outputs the posted data into the printed html, so you can put it somewhere in your body
Upvotes: 0