Jump to content

Radio Buttons in PHP post?


Riseykins

Recommended Posts

Okay.  If you had a form that looked like this:

<form action="test_handle.php" method="POST">
Are you human? <input type="radio" name="human" value="Yes" />Yes <input type="radio" name="human" value="No" /> No <br />
<input type="submit" name="SubmitForm" value="Submit!"
</form>

Notice how they have the same name, but different values.

<?php #test_handle.php
if (isset($_POST['human'])) {
  $human = $_POST['human'];
  switch $human {
         case "Yes":
          echo "Good thing you're human!";
          break;
         case "No":
          echo "Ah omg alien.";
          break;
         default:
           echo "Then what are you...";
           break;
   }
}
else {
echo "Please select an option next time.";
}
?>

 

Now, obviously, you could do more than that, but that should get you on the right track.

Link to comment
Share on other sites

I am not sure if i am getting the question right.

 

But if you want to make something to change while you select an option you can list the options available in a list box and make a simple java script for the onChange event.

 

If you need something like that tell me, i am willing to hlp.

 

cheers

Link to comment
Share on other sites

Glitter stye:<p />
Not here, yet!<p />

<form>
Text: <input type="text" name="word" size="8" /><p />
<input type="submit" name="btn" value="Submit" />
</form><p />

<div class="h1">Preview</div>
Click "submit" to see a preview.<p />
<?php
if (isset($_GET['btn']))
{
    $word = $_GET['word'];
    $x = strlen($word);
    for ($i=0; $i<$x; $i++)
    {
        $c = $word[$i];
        echo "<img src='http://www.burningviolet.com/glittergen/1/$c.gif' />";
    }
}
?>

<p />
<div class="h1">Code</div>

<textarea><?php
if (isset($_GET['btn']))
{
    $word = $_GET['word'];
    $x = strlen($word);
    for ($i=0; $i<$x; $i++)
    {
        $c = $word[$i];
        echo "<img src='http://www.burningviolet.com/glittergen/1/$c.gif' />";
    }
}
?></textarea>

 

 

The folder named "1" is the folder that I want to change depending on what radio button has been selected.

Link to comment
Share on other sites

Just an FYI, if you create a form and action to to a script with the following code, you'll see all the post variables displayed.

 

<?php
print_r($_POST);
?>

 

Once you can see the post values, view the source; it's easier to look at.

Link to comment
Share on other sites

With a form, you have to supply the action parameter, for example:

 

<form action="yourfile.php" method="post" name="yourform">

 

When the form is submitted, the values from the text fields, radio buttons etc. are all sent to the yourfile.php. You can then set this script to do things with those values.

 

For a list of the values, use the script i supplied previously, or you can get a value by using the following code:

 

<?php
$yourvariable = $_POST['yourfield'];
?>

Link to comment
Share on other sites

The thing that I'm finding hard is the fact that when you type a word in one box, an image is generated for each letter.

 

So, each letter URL generated will also need to be modified by selecting different radio buttons.

 

I just can't get it to list in the right order, so to speak...

 

I don't know if this makes any sense!

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.