Jump to content

Multiple Radio Buttons


dannyo101

Recommended Posts

I have a registration form for a tournament.  A user must input a persons name & age and indicate if that person is the captian.  The form will list 3 lines, 1 for each person.  I want to use a radio button to indicate if the person is a captain.  There can only be one captain.  I the way I have it now, the value is copied for every person.

 

Here is my code:

  for ( $id = 1; $id <= 5; $id += 1) {

echo '<tr><td>';

echo '<input type="hidden" name="p_id['.$id.']" value="'.$id.'">'.$id;

echo '</td><td>';

echo '<input name="fname['.$id.']" type="text" maxlength="20" id="fname['.$id.']" size="20">';

echo '</td><td>';

echo '<input name="lname['.$id.']" type="text" maxlength="20" id="lname['.$id.']" size="20">';

echo '</td><td>';

echo '<input type="radio" name="captain" id="captain['.$id.']" value="Y">';

echo '</td></tr>';

}

 

Here is how I'm posting the variables:

foreach($_POST['id'] as $f_id){

$p_id=$_POST['p_id'][$f_id];

$fname=$_POST['fname'][$f_id];

$lname=$_POST['lname'][$f_id];

}

 

$cpt=$_POST['captain'];

 

for ($i = 1; $i <= count($p_id); ++$i){

echo '<tr><td>';

echo $i;

echo '</td><td>';

echo $fname[$i];

echo '</td><td>';

echo $lname[$i];

echo '</td><td>';

echo $cpt;

echo '</td></tr>';

}

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

Even when I set the value attribute for each radio button to be different, the value is duplicated in my results.

 

I set the radio button to this:

        echo '<input type="radio" name="captain" id="captain" value="'.$id.'">';

 

In my results, the same number is duplicated.  I think the problem is with how I'm handling the $_POST.  Any thoughts?

Even when I set the value attribute for each radio button to be different, the value is duplicated in my results.

 

I set the radio button to this:

        echo '<input type="radio" name="captain" id="captain" value="'.$id.'">';

 

In my results, the same number is duplicated.  I think the problem is with how I'm handling the $_POST.  Any thoughts?

 

 

 

 

bleh, dunno

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.