Saving checkboxes |
[eluser]easymind[/eluser]
Once it worked, but now I am lost. I want to save checkboxes so I have a form like: Code: <form method="POST" action="somehwere.php"> Code: $this->input->post('id_categories');
[eluser]easymind[/eluser]
Ok hm. I found here http://www.phpfreakz.nl/ that it could be a server issue. If I try to get the array out of the $_REQUEST string, it works....
[eluser]Negligence[/eluser]
It says array because it is an array of values. You need to do: Code: $_POST['id_categories'][0] Don't use REQUEST.
[eluser]Michael Wales[/eluser]
But, it's just saying Array() - not outputting the values from that array, right (that's what I gathered).
[eluser]ejangi[/eluser]
I thought CI cleared the $_POST array as part of its' security measures??? So, wouldn't you then go: Code: echo "<pre>".print_r($this->input->post('id_categories'),1)."</pre>"
[eluser]Michael Wales[/eluser]
It doesn't clear $_POST, it just santizes it (so $_POST and $this->input->post return the exact same thing).
[eluser]ejangi[/eluser]
Yeah thanks Michael, immediately after posting that I went and checked the source of Input.php ![]() The other thing I wanted to ask Negligence is: When you get the blank Array(), have you checked any of the checkboxes? Cause I'm pretty sure the browser won't send any details about that form element unless it's been checked. I'm sure you've checked this, I just thought I'd double check... [EDIT]: That's a lot of "checks" in one sentence. ![]()
[eluser]Negligence[/eluser]
If you don't click a checkbox, it actually doesn't appear in the $_POST array at all. Not even as a null/empty value. easymind, I think the problem has to do with you doing an echo() and print_r() in the same statement. Anytime you try to echo() an array, it will print "Array". You should be doing this: Code: echo '<pre>'; And use a for/foreach loop to walkthrough the checkbox values.
[eluser]easymind[/eluser]
People, I am sure it was a server issue. If a $_POST variable is an array my server makes it a string. I really need to use the $_REQUEST variable to get my array.... This can be helpfull information for the rest of the 0,000001% of people who have this same problem....
[eluser]Negligence[/eluser]
I am telling you that you cannot print arrays using echo(), this isn't a bug. This is just the way PHP works. If you try to use echo() on an array, it will just print "Array". Use my code above and your problem will be solved. And I advise against using $_REQUEST because you don't actually know where the data is coming from. It's bad practice. |
Welcome Guest, Not a member yet? Register Sign In |