25 Jul Previewing more than one submited form containing images on the same page Posted by lisag | 4 Comments
Hi All,
I am new with PHP and Forms, so please bear with me.
I have a page with 2 forms(will be more like 20 later on) that user can sift through to choose the items in certain colors.Once selected, the submitted form will go to the correct destination page. I can't get both of the form submits to show up at the same time on this page! This concept is similar to choosing products from a catalog and adding to the shopping cart, less math and payment. I can get one or the other, just not both at the same time. Please let there be a simple solution...
Here is the code I have for the forms(both forms on on page):
form 1
<form action="closet_redes.php" method="post" Name = "tank" class="align">
<select name="tank">
<option value="none">Choose a Color</option>
<option value="black">black</option>
<option value="blue">blue</option>
<option value="red">red</option>
</select>
<input type="submit" name = "Tank" value = "Select Tank">
</form>
form 2
<form action="closet_redes.php" method="post" enctype="multipart/form-data" Name = "heels" class="align">
<select name="heels">
<option value="none">Choose a Color</option>
<option value="white">white</option>
<option value="hotpink">hotpink</option>
</select>
<input type="submit" name = "Heels" Value = "Select Heels">
</form>
Destination Body php:
<?php

if (isset($_POST['Submit'])) {

$tank = $_POST['tank'];

if ($tank == "black") {
print ("<IMG SRC =tank_transpar_bg/Tank_blk_t.gif>");
}
if ($tank == "blue"){
print ("<IMG SRC =tank_transpar_bg/Tank_blue_t.gif>");
}
if ($tank== "red"){
print ("<IMG SRC =tank_transpar_bg/Tank_red_t.gif>");

}
}


?>
if (isset($_POST['Submit'])) {

$heels = $_POST['heels'];

if ($heels == "white") {
print ("<IMG SRC =heels/heel_wht.gif>");
}
if ($heels == "hotpink"){
print ("<IMG SRC =heels/heel_hotpink.gif>");
}

}
?>

I figure it's an IF, ELSE statement I'm missing. I have no PHP above the HTML for this. Don't know how to go about it. Any suggestions would be greatly appreciated!!! I do want to keep the forms on one page.Looking forward to any input!!!!

4 Replies to "Previewing more than one submited form containing images on the same page"

Sasho Valkanov July 30, 2012 at 2:47 pm | Reply

+1

It seems that you may use one form only instead of 2 forms

<form action="closet_redes.php" method="post" Name = "tank" class="align">
<select name="tank">
<option value="none">Choose a Color</option>
<option value="black">black</option>
<option value="blue">blue</option>
<option value="red">red</option>
</select>

<select name="heels">
<option value="none">Choose a Color</option>
<option value="white">white</option>
<option value="hotpink">hotpink</option>
</select>
<input type="submit" name = "Heels" Value = "Select">
</form>


This way when form is submitted you will have both selections in the $_POST. However, if you want to do this as a multi step selection what you need to do is to pass the value from the first form onto the second form in a hidden field. This way when you submit the second form you will have the value from the first form in the $_POST again (the hidden field in the second form).
Lisa August 10, 2012 at 2:38 am

0

It worked!!! Thanks sooooooo much!
I am now able to wrap my head around forms, kinda:>)
I have another brain yeast for u if interested:
how do I get specific chosen form variables (echoes) to echo in a new location. Basically choosing From pre selected array and echoing that info in a different spot... I have no code right now, just trying to work out the logic and steps.
I will also want to copy that info into a new file to save to a users profile and have it easily accessible to share( as a gif)... Make sense???
Sasho Valkanov August 13, 2012 at 2:46 pm

0

<input type="hidden" name="heels" value="<?php echo $_POST["heels"]; ?>" />


This will create a hidden form field using the value submitted for Heels drop down.
lisag July 30, 2012 at 6:48 pm | Reply

0

Thanks for your help. I will try it out today!
I guess practice makes perfect, lol!
  • 1


Please be polite and helpful and do not spam or offend others. We promise you will be treated the same way.

Log in your free account or if you still haven't joined our Webmaster Community Reward Program, you can create your free account now.

Posting tip:
if you use code in your comments please put it in these tags [php], [sql], [css], [js]
PHP code example: [php] echo date("Y-m-d"); [/php]

Thank you,
~ PHPJabbers team ~