HTML checkbox – array

A couple of days ago, I had to fix a form another developer had created. The form utilised the checkbox input type which I rarely use. I came across an interesting way of storing the data which may be standard? Definitely foreign to me. If you append the array brackets [] to the end of the checkbox name section, example:

<input type="checkbox" name="colours[]" value="red">
<input type="checkbox" name="colours[]" value="blue">
<input type="checkbox" name="colours[]" value="green">

The data will be stored in an array for you to handle as you wish on the server side.

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>