Jump to content

How Would I Go About Accomplishing "Form Placement"


Brandon_R

Recommended Posts

I AM very new to PHP and wanting to know how would i go about doing this.

 

I Have a form with a specific amount of options IE A, B, C, D, E.

Now i want C to represent Carrot.

 

So If A User Chose C,  the php to return , "You Have Chosen Carrot" on the ?do=process page.

 

Any ideas on how to do this.

 

 

Link to comment
Share on other sites

<?php
if (isset($_GET['fruit']))
{
  $fruit = $_GET['fruit'];
  echo "You have chosen ".$fruit.".";
}

?>
<form method="GET" action="fruit_page.php">
Choose a letter:<select name="fruit">
<option value="Apple">A</option>
<option value="Bannana">B</option>
<option value="Carrot">C</option>
<!-- and so on... -->
</select>
<input type="submit" value="submit">
</form>

 

Something like that?

Link to comment
Share on other sites

Yes perfect but is there a way to also return the abbreviation in the php echo also. Something like "You Have Chosen C Which Stands For Carrots". Should of Said That In My First Post Also.

 

Thanks For All Your Help So Far.

Link to comment
Share on other sites

<?php
//changing it to post
if (isset($_POST['fruit']))
{
  $fruit = $_POST['fruit'];
  $fruits = explode(":",$fruit);
  echo "You have chosen ".$fruits[0]." which stands for ".$fruits[1].".";
}

?>
<form method="POST" action="fruit_page.php">
Choose a letter:<select name="fruit">
<option value="A:Apple">A</option>
<option value="B:Bannana">B</option>
<option value="C:Carrot">C</option>
<!-- and so on... -->
</select>
<input type="submit" value="submit">
</form>

 

I've never done anything like that before, but it seems like that would work. I'm sure there are better ways to do it.

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.