Hello,

I have a html form with radio buttons. This form is supposed to pass variables to php for processing. But here's my problem... php accepts variables from the form's NAME attribute. But since all radio buttons must have the same name, it means php has no way of differentiating between the different radio button choices. Is there a way around this? Can I get php to recognized the VALUE attribute from the form? Thx.
Richie.

    Look, the name of the radiobutton contains the value... understand what I'm saying?
    So if you got a button that look likes this:
    <input type="radio" name="somename" value="someval"> then the value of $somename is the string someval...

    But if you do like this:
    <input type="radio" name="somename" value="01"> and on the receive page do like this:

    if ($somename == '01') {
    $someothervar = "Heavy text here, the 01 is simply a shortcut to this";
    }

    and then you can do switch if you've got lots of numbers...

    Hope it helps, Arni

      I think you've misunderstood some of the concept of radio buttons.

      You can have multiple sets of radio buttons, each with a unique name.

      <input type="radio" name="test" value="1">
      <input type="radio" name="test" value="2">
      <input type="radio" name="test" value="3">

      Now, one - and only one - button can be selected at the same time. If you select the third, and post this to php,. $test will contain '3'. If you choose the first one, $test will contain '1'.

      If you have several radio-sets with different names, $<name> will contain the VALUE field of the button selected. You can also, of course, make these arrays;

      <input type="radio" name="test[test]" value="1">
      <input type="radio" name="test[test]" value="2">
      <input type="radio" name="test[test]" value="3">

      <input type="radio" name="test[moretest]" value="1">
      <input type="radio" name="test[moretest]" value="1">
      <input type="radio" name="test[moretest]" value="1">

      Now, $test[test] would contain the VALUE of wichever button selected in the first radio set, and $test[moretest] would contain the VALUE field of the selected button in the last set.

      This is useful if you're generating (advanced) dynamic forms, and don't want to keep track of an infinite number of variables. E.g. name a textfield $text[first], a selectlist $list[first] and a textarea $textarea[first],.. etc.. Hmm.. My point apparently disappeared somewhere between here and the beginning, sorry.. 😉

        Yes Arni, that makes sense. I'll try that and see. Thx a bunch.
        Richie.

          6 days later

          I'm having troubles with the radio buttons for my application.
          Example:
          <input type=radio name=cars value=...camaro.htm>

          <input type=radio name=cars value=...mustang.htm>

          Now when the client selects one they will directed to a new page, based on their choice.
          I thought it would be something like:
          <?
          header("location: $cars");
          exit;
          ?>
          But this doesn't work. Any ideas.
          Thanks matt

            a month later

            Hi

            Thats how I thought that would work, I can see the Var in the address bar when i submit the code.

            However when i ty IF statements or even try to show the var using $variable there is nothing there!

              Write a Reply...