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.

 

 

<?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?

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.