Jump to content

Checking radio buttons


Go to solution Solved by taquitosensei,

Recommended Posts

Hi all

 

I have a simple HTML form, but have around 250 radio buttons, which are all needed.

 

All the radio buttons have different "name" attributes.

 

How can I run a check to make sure at least one of the radio buttons has been selected? Is this possible without passing the "name" attribute?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/279840-checking-radio-buttons/
Share on other sites

  • Solution

How are you generating your form? You can always create an array of the names. Then loop through and check for them.

$radio_array=array("radio1","radio2","etc");
$selected=False;  
foreach($radio_array as $radio) { 
   if(isset($_REQUEST[$radio] && $_REQUEST['radio'])) { $selected=True; }
}

if($selected) { 
   // do whatever you need to do here.
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.