Jump to content

Showing a Picture based on dropdown form after submit


bine.heckmann

Recommended Posts

Hello there,

 

I'm trying to show a picture based on the value that was chosen in the dropdown menu of the page before the submit.

 

Let's say i'm having a drop down form with 3 values: Porsche, BMW, Audi, the form also consists of a button to submit form and some other text fields but these aren't really relevant.

 

So what i want is, you choose whatever car, let's say BMW, fill in all the other data of the form, hit submit, and on the next page it should show a Picture which i define for each car.

 

I hope i explained that somehow understandable.

 

Thanks in advance,

 

Sabine

Link to comment
Share on other sites

Ok then, my form:

 

 <select name="fahrzeug" class="dropdownform" id="fahrzeug">
<option value="Audi" selected>Audi</option>
<option value="BMW">BMW</option>
          <option value="Porsche">Porsche</option>
          </select>

 

I'm not using any Database.

 

I'm thinking about something like this:

 

<?php
$picture= array("BMW"=>"pictureurl", "Porsche"=>"pictureurl", "Audi"=>"pictureurl");
$fahrzeug = $_POST['fahrzeug'];
echo $picture[$fahrzeug];
?>

 

Would that work ? And how would i have to put the pictureurl in that code, sorry i'm quite a noobie.

Link to comment
Share on other sites

Yes, that would work. I just expanded your code a little bit so you can get a better idea of what to do. You were headed in the right direction, though.

 

<?php
$photos = array('Audi' => 'Audi_picture.jpg', 'BMW' => 'BMW_picture.jpg', 'Porsche' => 'Porsche_picture.jpg');
if( isset($_POST['fahrzeug']) ) {
$display = $photos[$_POST['fahrzeug']];
}
echo "File name: $display<br>";
?>

<img src="path/to/your/images/<?php echo $display; ?>">

<form action="" method="POST">
<select name="fahrzeug" class="dropdownform" id="fahrzeug">
<option value="Audi" selected>Audi</option>
<option value="BMW">BMW</option>
<option value="Porsche">Porsche</option>
</select>
<br>
<input type="submit" value="submit" name="submit">
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.