1

EDIT: I never got this working, it appears that "boxes" was not an array on the PHP side, instead was a String that said "Array." I switched to an AJAX solution and no longer need this answer. It will now be closed

So, this seems like a very simple question, but I have checkboxes generated from php in a form, then re-submitted to a php script for processing. Unfortunately, the array of checkboxes is EMPTY.

Here is my generated form code. (NOTE: the action is empty because its the same php file):

<form method="POST">
<input type="hidden" name="multi" value="1"> <-- Ignore this -->
<input type="hidden" name="test" value="1">  <-- Ignore this -->
<input type="hidden" name="EMAIL" value="[email protected]">
<input type="hidden" name="FNAME" value="John">

<input type="checkbox" name="boxes[]" value="Jennifer and Friends"> Jennifer and Friends<br>
<input type="checkbox" name="boxes[]" value="Worship with Rachel"> Worship with Rachel<br>
<input type="checkbox" name="boxes[]" value="Jim Gerhold: Relationship"> Jim Gerhold: Relationship<br>
<input type="checkbox" name="boxes[]" value="Maximize Others Leadership Resources" checked=""> Maximize Others Leadership Resources<br>
<input type="submit" value="Save">
</form>

Now when I print_r the $_POST array I get the following input:

Array
(
    [multi] => 1
    [test] => 1
    [EMAIL] => <REMOVED>
    [FNAME] => <REMOVED>
    [boxes] => Array
)

And... in the chrome developer tool, I see the form data correctly:

Chrome Form Data

And finally, a var_dump of $_POST['boxes'] returns

string(5) “Array”

Does anyone know how to retrieve the array, or why it is not appearing as a normal php array?

6
  • 2
    What is your question? Also, you should post your PHP too. Commented Jul 21, 2014 at 15:21
  • 1
    How do you know its empty? Try var_dump instead of print_r Commented Jul 21, 2014 at 15:22
  • by the looks of it, it's not empty, it has an array type inside it [boxes] => Array Commented Jul 21, 2014 at 15:24
  • try this var_dump($_POST['boxes']); to see if the array is empty Commented Jul 21, 2014 at 15:24
  • @Nicolas My question is why cant I transverse the array. My php right now is just the print_r. var_dump returns string(5) “Array”. It seems like the contents is "Array". If I echo $_POST['boxes'][0] it returns 'A', then 'r'... and eventually prints Array Commented Jul 21, 2014 at 16:02

1 Answer 1

2

It's not empty, and I quote directly from your print_r($_POST) output:

[boxes] => Array

You can loop through the contents with:

foreach($_POST["boxes"]) { ... }

or print the contents using:

print_r($_POST["boxes"]);

While it is outside the scope of your question, I would recommend using var_dump() next time. var_dump traverses sub-arrays and formats nicely in <pre></pre> tags.

Sign up to request clarification or add additional context in comments.

1 Comment

Running a var_dump returns string(5) “Array”.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.