PHP Classes

Radio button processing

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  Radio button processing  >  (Un) Subscribe thread alerts  
Subject:Radio button processing
Summary:I can seem to get the radio button values
Messages:5
Author:Tobbe
Date:2009-10-28 14:51:16
Update:2009-10-30 20:52:56
 

  1. Radio button processing   Reply   Report abuse  
Picture of Tobbe Tobbe - 2009-10-28 14:51:16
Definition of radiobuttons:
----
$form->AddInput(array(
"TYPE"=>"radio",
"NAME"=>"cr_type",
"ID"=>"cr_type_new",
"VALUE"=>"NEW",
"CHECKED"=>0,
"ValidateAsSet"=>1,
"ValidateAsSetErrorMessage"=>
"Du måste välja en Ändringstyp",
"LABEL"=>"<u>N</u>y",
"ACCESSKEY"=>"N"
));

$form->AddInput(array(
"TYPE"=>"radio",
"NAME"=>"cr_type",
"ID"=>"cr_type_change",
"VALUE"=>"CHANGE",
"LABEL"=>"<u>Ä</u>ndring",
"ACCESSKEY"=>"N"
));

$form->AddInput(array(
"TYPE"=>"radio",
"NAME"=>"cr_type",
"ID"=>"cr_type_del",
"VALUE"=>"DEL",
"LABEL"=>"<u>R</u>adera",
"ACCESSKEY"=>"N"
));

------

This doesn't show anything when form is submitted:
echo "<br>test: ".$form->GetSubmittedValue('cr_type');

Other values from other input types seems go work fine.

I'm a little confused about when to use ID and when to use name, could that be an issue here?

Hope you can help with this!

  2. Re: Radio button processing   Reply   Report abuse  
Picture of Tobbe Tobbe - 2009-10-28 14:53:44 - In reply to message 1 from Tobbe
Btw, if I do this:

echo $_POST['cr_type'];

I do get the value, so at least it is POSTed from the form. I just need to be able to retrieve it without having to resort to $_POST variable...

  3. Re: Radio button processing   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-10-28 17:31:19 - In reply to message 1 from Tobbe
Since you never know which radio button is checked, you need to use a different function like GetCheckedRadio or GetCheckedRadioValue.

  4. Re: Radio button processing   Reply   Report abuse  
Picture of Tobbe Tobbe - 2009-10-30 08:36:34 - In reply to message 3 from Manuel Lemos
Thanks for your reply.

I still can't get this to work.

Here is my test:
echo "<br>test GetCheckedRadioValue: ".$form->GetCheckedRadioValue("cr_type");
echo "<br>test GetCheckedRadio: ".$form->GetCheckedRadio("cr_type");
echo "<br>test \$_POST: ".$_POST['cr_type'];

And here is the output:
test GetCheckedRadioValue:
test GetCheckedRadio:
test $_POST: NEW

All other input types are displayed correctly using the GetSubmittedValue method.

Regards
Tobbe

  5. Re: Radio button processing   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2009-10-30 20:52:56 - In reply to message 4 from Tobbe
When the form is submitted, you need to call first $form->LoadInputValues(1); so the class can check which radio button was set.