echo in a chkbox

I would like to display whether an element(s) in a checkbox array was previously selected. I have my html code in an include so I would like to use $_POST[] if possible. I can do text using isset($_POST[]) but can’t do it with the checkbox array. I don’t want to have to assign an array to the $_POST[hrbox] because of the include. (I want to be able to include this onto several pages.) Here’s my code:

<?php if (isset($_POST['hbox[14]'])) echo 'checked'; ?>

(note: can you use a subscript in a POST? It doesn’t seem to work.)

When the isset didn’t work, I tried array_key_exists but got an error that hbox was not defined.

> ..

Thanks,

Bruce

Here is what you need to do…

First for the actual form:

<input type="checkbox" name="hbox[12]" value="1">

The value of the input can be anything because you just need to know if it is set and you can get the array’s key when you need it.

To see if it is checked:
[php]

<?php if( isset( $_POST['hbox'][12] ) ) echo 'checked'; ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service