Re: How do I display radio button results?
- From: Pedro Graca <hexkid@xxxxxxxxxxx>
- Date: 30 Oct 2006 17:17:03 GMT
Bob Sanderson wrote:
I have a form which uses several radio buttons to enter data. It works fine
as far as entering goes, but I can't figure out how to display which button
is checked when I view the record. I could do a if-then routine but it
seems like there should be an easier way.
Any help will be greatly appreciated.
What's your HTML like and how are you dealing with it in PHP?
This (with possible unintended errors corrected) works:
<!-- HTML, assume correct DOCTYPE, ... -->
<form ...>
<div class="group1">
<label><input type="radio" name="r[0]" value="0" checked>none</label>
<label><input type="radio" name="r[0]" value="1">one</label>
<label><input type="radio" name="r[0]" value="1">two</label>
</div>
<div class="group2">
<label><input type="radio" name="r[1]" value="0" checked>none</label>
<label><input type="radio" name="r[1]" value="1">one</label>
<label><input type="radio" name="r[1]" value="1">two</label>
</div>
<!-- some submit button -->
</form>
And the PHP that deals with it could be
<?php
foreach ($_POST['r'] as $k=>$radio) {
echo 'For group ', $k, ', you selected the option with ',
$radio, " for its value.<br>\n";
}
?>
--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
.
- References:
- How do I display radio button results?
- From: Bob Sanderson
- How do I display radio button results?
- Prev by Date: Re: Help me with a regular expression for PHP
- Next by Date: Re: what does it mean fieldRequired.lenght in php 4.1 ?
- Previous by thread: How do I display radio button results?
- Next by thread: Get http response codes
- Index(es):