Jump to content

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

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.