0

Hi guys,

Hope you can help (and hope I can explain my problem OK!)

I am designing a sports site which takes three values from a user to input match details: a date (text input), a versus (text input), and if the match is home or away (radio buttons). Several matches can be inputed in one page, so I am trying to pass my PHP script three arrays (date, versus, and home/away). For the text input I simply name the inputs "date[]" and "versus[]", however am struggling with the radio inputs.

Basically if I name all the radio buttons "homeaway[]", they are all part of the same set and so I can only select one option (when I want to be able to select one option per home/away pair), so I need a different name per pair, however then I cannot add it to a single array!

Does anyone have any suggestions? I would preferably avoid "homeaway1[]", "homeaway2[]", etc. as the number of match inputs per page is dynamic using JavaScript.

Hope I have made myself clear!

Thanks in advance.

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by dshiells
0

Could you post whatever code you've done so that we can get a clearer picture?

if you want all of the radio in one array that you may have to make it a multidimensional array.

ex: the input name

option[home][] and option[away][]

2

I think this is the way to go, however, I'd do it slightly differently:

No labels used, but you'll get the idea:

<?php

if(isset($_POST['sub_it'])){
  print_r($_POST);
}
?>

<form method="post">
<input type="date" name="date[]" />
<input type="text" name="versus[]" />
<input type="radio" name="ha[0]" value="home" checked="checked" />
<input type="radio" name="ha[0]" value="away" />
<br />
<input type="date" name="date[]" />
<input type="text" name="versus[]" />
<input type="radio" name="ha[1]" value="home" checked="checked" />
<input type="radio" name="ha[1]" value="away" />
<br />
<input type="date" name="date[]" />
<input type="text" name="versus[]" />
<input type="radio" name="ha[2]"  value="home" checked="checked" />
<input type="radio" name="ha[2]" value="away" />
<input type="submit" value="go" name="sub_it" />
</form>

This can be easily created with a php for loop:

$groups = "";
for($x=0;$x<6;$x++){
  $groups .= "<input type=\"date\" name=\"date[]\" />\n
<input type=\"text\" name=\"versus[]\" />\n
<input type=\"radio\" name=\"ha[$x]\" value=\"home\" checked=\"checked\" />\n
<input type=\"radio\" name=\"ha[$x]\" value=\"away\" />\n";
}

....


echo $groups;

Edited by diafol: n/a

Votes + Comments
Understood and answered my question perfectly!
0

Hi guys,

Thanks for your replys! I have given ardav's way a go and it works perfectly (i.e. produces: Array ( [0] => away [1] => home [2] => away [3] => home )).

Thanks so much for your help, right on the money!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.