CodeIgniter Forums
Radio Buttons with Other (please specify) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Radio Buttons with Other (please specify) (/showthread.php?tid=2985)



Radio Buttons with Other (please specify) - El Forum - 09-03-2007

[eluser]K-Fella[/eluser]
How would I go about dealing with a form that has a group of radio buttons where one is set to 'Other' with a seperate input field provided?

How can I validate that the input field has been populated if the 'Other' radio button has been selected?


Radio Buttons with Other (please specify) - El Forum - 09-03-2007

[eluser]Nillian[/eluser]
Could you not just check your POST data to see if the 'Other' button was selected (using an IF statement), and then validate the Other field if the radio button has been selected? Or perhaps I misunderstand?


Radio Buttons with Other (please specify) - El Forum - 09-04-2007

[eluser]K-Fella[/eluser]
What I would like to do is use the validation library, but I don't know how to do it. At the moment it does a callback to check if no buttons were selected. But because the 'Other' input field is seperate from the group of radio buttons, it has it's own POST value. Therefore I don't see a way of setting up a rule that checks if one rule equal 'Other' to check another rule. Can a callback invoke another callback? If so, this would work.


Radio Buttons with Other (please specify) - El Forum - 09-04-2007

[eluser]Michael Wales[/eluser]
Yes - use the callbacks for it.

Code:
function __callback1() {
  return $this->__callback2();
}

function __callback2() {
  return TRUE;
}

Should work - give it a try.