Page 1 of 1

Form not creating array properly

Posted: Fri Apr 04, 2008 5:11 pm
by goodwinpro
This is a strange problem and I'm not sure where to look for the answer.

<form method="post" action="process.php">
<input type="checkbox" name="recid" value="44"/>
<input type="checkbox" name="recid" value="35"/>
<input type="checkbox" name="recid" value="25"/>
<input type="checkbox" name="recid" value="80"/>
</form>


I want to take this data and loop it.

My process page code is:

$data = array($_REQUEST['recid']);
foreach ($data as $val )
{
echo '<br> Data: '.$val.'<br>';
}


But my array only displays the last value (in this case 80). I can't get more than one value to display.

When I change method to GET I get:
?recid=44&recid=35&recid=25 on the URL. But still only get the last value to display.


Any ideas?
Thanks.

Re: Form not creating array properly

Posted: Fri Apr 04, 2008 5:32 pm
by Christopher

Code: Select all

<form method="post" action="process.php">
<input type="checkbox[]" name="recid" value="44"/>
<input type="checkbox[]" name="recid" value="35"/>
<input type="checkbox[]" name="recid" value="25"/>
<input type="checkbox[]" name="recid" value="80"/>
</form>

Re: Form not creating array properly

Posted: Fri Apr 04, 2008 5:40 pm
by goodwinpro
Ok, tried this...

Code: Select all

<form method="post" action="untitled.php">
<input type="checkbox[]" name="recid" value="44"/>
<input type="checkbox[]" name="recid" value="35"/>
<input type="checkbox[]" name="recid" value="25"/>
<input type="checkbox[]" name="recid" value="80"/>
</form>
but it produced a bunch of text boxes on my form page and still only showed the last value. I wanted them as checkboxes. Am I missing something?

Re: Form not creating array properly

Posted: Wed Apr 09, 2008 3:18 pm
by goodwinpro
Can anybody give me a working example that I can reference? I think I have it right, but I may have missed something.

Are there any settings in the PHP.ini file that affect how variables build arrays? I couldn't find any, but I'm not sure what to look for either.

Any ideas? This problem is really starting to hurt.

Thanks
Rob

Re: Form not creating array properly

Posted: Wed Apr 09, 2008 4:19 pm
by John Cartwright
typo by arborint

Code: Select all

<form method="post" action="process.php">
  <input type="checkbox" name="recid[]" value="44"/>
  <input type="checkbox" name="recid[]" value="35"/>
  <input type="checkbox" name="recid[]" value="25"/>
  <input type="checkbox" name="recid[]" value="80"/>
</form>

Re: Form not creating array properly

Posted: Wed Apr 09, 2008 5:01 pm
by Christopher
Jcart wrote:typo by arborint
:mrgreen:

Re: Form not creating array properly

Posted: Thu Apr 10, 2008 10:57 am
by goodwinpro
BINGO! THANKS! That one worked.
Exactly what I was looking for.

I really appreciate the help. :D