/    Sign up×
Community /Pin to ProfileBookmark

Drop down Menu’s Form — Multiple Options (need PHP form for submit)

Im sorry if the subject didnt explain this well… but in so little words i couldnt find a better way to do it. Basically what I want to do is on this page :

Neoitems.net … its to the very right in the second block where it says ‘pet colors’. Two drop downs, one submit, and i want the image to show up by the form. I know how to make the form and how to link it up to the PHP documnet… I just don’t know what PHP form I need to use to accomplish this. Hopefully I have explained this well enough… if i havent please let me know and I will try and go into better detail. If there is a site you can give me that shows what form to use or how to make one that will do just fine…

Thanks so much!!

to post a comment
PHP

16 Comments(s)

Copy linkTweet thisAlerts:
@PunkSktBrdr01Oct 04.2003 — Do you mean you want to dynamically generate an image based on the form input? This would be really hard, but it might be possible. Or maybe not. Lemme know if that's what you want.
Copy linkTweet thisAlerts:
@GreyFaerieauthorOct 05.2003 — i want exactly what is on the site i posted... i will prolly have the image show up to the right though
Copy linkTweet thisAlerts:
@Kr_ZOct 05.2003 — First, you have to make all the images you want to use in all the colors you want to be selectable. Then when a user submits the form, lets say he has selected "Acara" and "Baby", the php-script shows the image "acara_baby_happy.gif".
Copy linkTweet thisAlerts:
@GreyFaerieauthorOct 05.2003 — that helps... but i dont know how to write the script at all ? should i just give up ? I have all the images and everything... so basically im set i just need the php
Copy linkTweet thisAlerts:
@Kr_ZOct 05.2003 — You just need a few lines of code.

In this example I have a circle and a square in 3 different colors.

1.Set up the form:

[CODE]
<form method="post" action="index.php">

<select name="object">
<option value="circle" >Circle</option>
<option value="square">Square</option>
</select><br>

<select name="color">
<option value="red" >Red</option>
<option value="blue">Blue</option>
<option value="green" >Green</option>
</select>

<input type="hidden" name="submitted" value="1">
<input type="submit" value="Go!">

</form>
[/CODE]


  • 2. The php code:


  • [code=php]
    <?php

    // The folder with all the images in
    $folder = "images/";

    if(isset($_POST["submitted"])) {

    print("<img src="".$folder.$_POST["object"]."_".$_POST["color"].".gif">");

    }

    ?>
    [/code]


    Now, if I had selected a red circle, it would show an image called images/circle_red.gif
    Copy linkTweet thisAlerts:
    @GreyFaerieauthorOct 06.2003 — wow thanks!! that helps out sooooo much. thanks for your time!
    Copy linkTweet thisAlerts:
    @GreyFaerieauthorOct 06.2003 — Ok... i will have two drop downs in the form with select names "Pet" and "Colour".

    Then all the file names have this basic format for their file name:

    pet_colour_happy.gif

    The 'pet' and 'colour' parts of the file name change (with the php code) while the 'happy' part stays the same.

    and ex: (blumaroo, kacheek, and acara are pets)

    blumaroo_brown_happy.gif

    kacheek_green_happy.gif

    acara_blue_happy.gif

    so what im asking is how do i get the 'happy' into the php code? everyting is perfect in the first one you gave me... i just need to find a way to get that last part of the file name in there

    hopefully I explained this well..
    Copy linkTweet thisAlerts:
    @PunkSktBrdr01Oct 07.2003 — Add a new select list for the moods, and in the PHP code, replace

    [code=php]
    print("<img src="".$folder.$_POST["object"]."_".$_POST["color"]."_".$_POST["mood"].".gif">");
    [/code]
    Copy linkTweet thisAlerts:
    @GreyFaerieauthorOct 07.2003 — ok... im doing something wrong. if you could help me I would be ever so greatful....

    This is the form on a page i named PetColours.htm ...

    <div align="center">

    <form method="post" action="/petcolours.php">

    <select name="Pet" id="Pet">

    <option value="acara">Acara</option>

    <option value="aisha">Aisha</option>

    </select>

    <SELECT NAME="colour">

    <option value="red">Red </option>

    <option value="green">Green </option>


    </SELECT>

    <br>

    <br>

    <input type="submit" name="Go!" value="Go!">

    <br>

    <br>

    </form>

    </div>

    Here is the PHP file ...

    <?php

    // The folder with all the images in

    $folder = "http://images.neopets.com/pets/happy/";

    if(isset($_POST["submitted"])) {

    print("<img src="".$folder.$_POST["Pet"]."_".$_POST["Colour"]."_baby".".gif">");

    }

    ?>
    Copy linkTweet thisAlerts:
    @PunkSktBrdr01Oct 07.2003 — In PetColours.htm, change the name of the submit button to "submitted".
    Copy linkTweet thisAlerts:
    @GreyFaerieauthorOct 07.2003 — its just sending me to a blank page.... goto www.playingwithfaeries.com/PetColours.htm to see what im talking about
    Copy linkTweet thisAlerts:
    @Kr_ZOct 07.2003 — Have you changed this line like PunkSktBrdr01 said?

    <input type="submit" name="Go!" value="Go!">

    to

    <input type="submit" name="submitted" value="Go!">
    Copy linkTweet thisAlerts:
    @PunkSktBrdr01Oct 07.2003 — Okay, I found the problem. You still have the name for the submit button wrong. It needs to be "submitted" all in lowercase. PHP variables are case sensetive, so "Submitted" (what you have) is not the same as "submitted". It's a simple mistake, but it prevents the script from working.
    Copy linkTweet thisAlerts:
    @GreyFaerieauthorOct 07.2003 — thanks so much for your help... and yes it works now. but i guess im getting myself into more trouble... becuase i want the image to show up to the right of the image. Ive updated the page to what i am trying to do so you can take a look. i decided maybe using an iframe would work... if there is a better way please let me know. anyway... when the fram first opens up the image i have linked to it works but when you try to submit the form i get a 'page cannot be displayed' in the iframe. here is what i got and i havent changed anything in the php file..

    I linked the form to load in the iframe :

    <form method="post" action="/petcolours.php" target="images">

    <select name="Pet" id="Pet">

    <option value="acara">Acara</option>

    <option value="aisha">Aisha</option>

    ....

    And here is the code i used for the iframe:

    <iframe src="http://images.neopets.com/pets/happy/kacheek_yellow_baby.gif" scrolling="no" name="images" width="160" height="170" frameborder="0">

    </iframe>

    Can you please help? thanks so much to all of you... for your time and your extertise. I greatly appreciate it
    Copy linkTweet thisAlerts:
    @PunkSktBrdr01Oct 07.2003 — Looks good! It's working fine for me. I'm using Mozilla Firebird 0.6.1.
    Copy linkTweet thisAlerts:
    @GreyFaerieauthorOct 08.2003 — oh wow... so it is! lol... i dont know what i did but i obviously did something right... lol. but all i know is that i couldnt have done it without you... thanks so much ?
    ×

    Success!

    Help @GreyFaerie spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...