Jump to content

Passing multiple radio values in a form..

- - - - -

  • Please log in to reply
1 reply to this topic

#1
DavidJ

DavidJ

    Newbie

  • Members
  • Pip
  • 1 posts
Hey guys, Im pretty new to PHP and I seem to be having a small problem in passing radio button values in a questionaire style page.

Basically what i am trying to achieve is to have:

Question 1:
User 1: () () () () ()
User 2: () () () () ()

Question 2:
User 1: () () () () ()
User 2: () () () () ()

Where the brackets obviously represent radio buttons. As i understand it, in order to store the results, i somehow need to send the question_id, the user_id and the actual value of the radio button(which is 1-5).

At the moment i have my radio buttons named:

<input type="radio" name="'.$get_name_row['0'].'|'.$i.'|'.$get_questions_row['0'].'" value="1">

<input type="radio" name="'.$get_name_row['0'].'|'.$i.'|'.$get_questions_row['0'].'" value="2">

<input type="radio" name="'.$get_name_row['0'].'|'.$i.'|'.$get_questions_row['0'].'" value="3">

And was hoping to split the string based on the | character i am placing between each value. However this poses the question of retrieving it on the other side of the form, as the recieving script has no way of retrieving the value because it doesnt know what to put in the $_REQUEST['']. Am I being a complete idiot here and over complicating it?

Many thanks, David

#2
rySch

rySch

    Newbie

  • Members
  • Pip
  • 8 posts
Hi David,
What exactly are you trying to achieve?

Are you trying to dynamicly generate the radio buttons?

Looking at your code, you change the name value of each input, this needs to stay the same per group of radio buttons, ex:


<input type="radio" name="radio_1" value="1" />

<input type="radio" name="radio_1" value="2" />

<input type="radio" name="radio_1" value="3" />

<input type="radio" name="radio_2" value="1" />

<input type="radio" name="radio_2" value="2" />

<input type="radio" name="radio_2" value="3" />


alternatively if your looking to make the radio buttons using a pre defined/gotten array use this

$radio = array('1','2','3','4','5'); //values for the radios

foreach($radio as $k){

    echo '<input type="radio" name="radio_1" value="'.$k.'" />';

}

Again im not 100% sure on what your trying to do, if the above are not what your after please clarify :)

Ryan,




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users