I cannot find the correct way of accessing my checkbox array.
The form has an array of checkboxes which is shown in source HTML like this:
<div class="form-item">
<label class="option"><input type="checkbox" class="form-checkbox" name="edit[state]" id="edit-state" value="1" /> State, province or region</label>
</div>
In my actioned script the only way I can access the resulting array is as using:
$data = serialize($_POST['edit']);
The output of this (with realname and address checkboxes ticked) is as follows:
a:5:{s:8:"realname";s:1:"1";s:7:"address";s:1:"1";s:4:"city";s:1:"0";s:5:"state";s:1:"0";s:7:"country";s:1:"0";}
It can clearly be seen that the realname and address data has a value of "1", whereas the other non-checked boxes have zeroes.
This proves my data is there. But I cannot access it as an array - I think I've tried everything - but clearly not quite the right syntax.
The nearest I have got results in
key = '0' and value = 'array' - which is clearly an incorrect assignment of some sort.
It must be simple..Can anyone help? I've been at it for two days!!
Thankyou...
Update...No idea why it would'nt work because this was one of the first things I tried! Don't you just love it?!!
Here it is for any0ne that's interested as simple solutions are so hard to find when your stuck:
if ($_POST['op']) {
$data = $_POST['edit'];
while ($element = each ($data)) {
$output .= $element['key'];
$output .= '-';
$output .= $element['value'];
$output .= '<br />';
.....
where $output is the output string for printing.
This results in:
realname-1
address-1
city-0
state-0
country-0
(Bear in mind no security or validation going on here)