Here's my situation, I have a list of features for vehicles that I store in a table in the database. On my html form, I want to display these features as a list of checkboxes that the users can select based on the features they have on their vehicle.

Now this is my problem, on this form there are fields for year, price and so forth, which require validation. I'm using sessions to store the values entered, and if there are errors, I redisplay the values they entered using the session array. This isn't a problem with the year, price and other fields where they enter text, but how do I go abouts doing this with checkboxes, since it seems like a can't pass an array back and forth in the http header?

I want the checkboxes that the user selected to be selected when they are taken back to that page agian if there were errors.

    The problem, as I understand, is The check box when you don't check it, its value will not be passed to the action page of your form. and more the next checked value will occupay the place of unchecked one.
    to solve all this stuff of problems you will do the following:
    1) name your forms elements as array name
    e.g<input type="checkbox" name="chek[]" value="ys">
    2)Make a refference element, to tell the action page which Checkbox was checked and which is not. this may be done using a hidden field. its value will equals to the value of check box.
    so when the checkbox is not checked, the respective hidden field value will differ than the value of the next checkbox so by a simple code you will able to identify the sented item.

      Write a Reply...