Sublime directory Surf the web anonymous Pagerank Monitor


Checkboxes working but cannot get radio groups working

scheluka
Fri 21 September 2007, 03:43 pm GMT +0200
I have been through the demo, worked on the examples, but just cannot get radio buttons to work correctly, have any body managed to get that right.
Checkboxes no problem, but the radio is getting the better of me. Is there someone whom had the same problem that got it to work.

It would be much appreciated.

olaf
Fri 21 September 2007, 07:42 pm GMT +0200
??? those two types of elements are almost the same (actually much easier). Please give an example

scheluka
Thu 6 December 2007, 12:22 pm GMT +0100
My apologies for only getting back so long afterwards. :-[
If we implement the radio as per the example, it works. The only problem is should the user fail to complete any other field
and the form refresh and output the error, the radio button selection defaults to the last radio field. So if I selected Yes, then it will jump and select Maybe as checked.
This also happens on the submit. Some guidance on where im making my mistake will be much appreciated.

We have used the following code:
In the validation I set the following:
$example->add_check_box("Radio button test", "choice", "radio", "");

And in the form I have used:
<label for="choice">A Radio (required)</label>
Yes <input name="choice" type="radio" id="check" value="y"<?php if (isset($_POST['choice'])) echo " checked"; ?>>
No <input name="choice" type="radio" id="check" value="n"<?php if (isset($_POST['choice'])) echo " checked"; ?>>
Maybe <input name="choice" type="radio" id="check" value="m"<?php if (isset($_POST['choice'])) echo " checked";?>><br clear="all">

olaf
Thu 6 December 2007, 12:37 pm GMT +0100
don't check only for an exsiting value but also what value is available

like
if (isset($val) && $val == 'some value') echo 'yes';

scheluka
Thu 6 December 2007, 01:02 pm GMT +0100
Thanks so much , especially for the very swift response, its much appreciated. For the benefit of the community, we have amended the code to the following and it works great! Many thanks again. Such a quick fix, don't know how we missed that.

<label for="choice">A Radio (required)</label>
Yes <input name="choice" type="radio" id="check" value="y"<?php if (isset($_POST['choice']) && $_POST['choice'] == 'y') echo " checked"; ?>>
No <input name="choice" type="radio" id="check" value="n"<?php if (isset($_POST['choice']) && $_POST['choice'] == 'n') echo " checked"; ?>>
Maybe <input name="choice" type="radio" id="check" value="m"<?php if (isset($_POST['choice']) && $_POST['choice'] == 'm') echo " checked"; ?>><br clear="all">

olaf
Thu 6 December 2007, 01:25 pm GMT +0100
you're welcome I think people like this solution much more :D

http://www.finalwebsites.com/snippets.php?id=48

mmccss
Sat 22 December 2007, 08:21 pm GMT +0100
Hi ,
i have a group of radio input bet i have a problem when i submitted the form if i have selected second radio input validation returns with error;but if i have selected the first radio input everyting is okay.

i have used the class like this

$example->add_check_box("Example", "test", "radio","");

<input name="test" type="radio" id="test" value="1" <?php if (isset($_POST['test']) && $_POST['test'] == '1') echo " checked"; ?> />No
     
<input name="test" type="radio" id="test" value="0" <?php if (isset($_POST['test']) && $_POST['test'] == '0') echo " checked"; ?> /Yes
   
I don't understand where is the problem...

EDIT
I solved the problem radio inputs value = 0 giving errors i changed values 1 and 2 so its worked...

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional