Forum Moderators: open
- option 1
- option 2
- option 3
These have id and name tags of id="option[1]", id="option[2]", id="option[3]" and name="option[1]", name="option[3]", name="option[3]" so that I can use the html label tag and attach a label to each checkbox via for="option[1]", etc.
This seems to work perfectly in terms of passing me an array of values upon submission, and the labels are all properly tied to the checkboxes... my problem is validation.
I know it's not a big deal, but would love this doc, as complicated as it is, to validate. The error I get is:
character "[" is not allowed in the value of for If I remove the [] from the for attribute of the labels, they don't tie in with the inputs...
Any suggestions?
Thanks!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
form {
width: 200px; margin: 5%;
}
</style>
</head>
<body>
<form action="">
<fieldset>
<legend>Check Boxes</legend>
<input type="checkbox" id="option1" />
<label for="option1">Options 1<br /></label>
<input type="checkbox" id="option2" />
<label for="option2">Option 2<br /></label>
<input type="checkbox" id="option3" />
<label for="option3">Option 3</label>
</fieldset>
</form>
<!--##########
I have an XHTML 1.1 strict document that has a number of checkboxes in it that are all linked together(the user can select multiple options), ie:
- option 1
- option 2
- option 3These have id and name tags of id="option[1]", id="option[2]", id="option[3]" and name="option[1]",
name="option[3]", name="option[3]" so that I can use the html label tag and attach a label to each checkbox via for="option[1]", etc.
This seems to work perfectly in terms of passing me an array of values upon submission, and the labels are all properly tied to the checkboxes... my problem is validation.
I know it's not a big deal, but would love this doc, as complicated as it is, to validate. The error I get is:
character "[" is not allowed in the value of for
If I remove the [] from the for attribute of the labels, they don't tie in with the inputs...
-->
</body>
</html>
First, here's how things are happening right now:
User hits form page, php goes to db and grabs options, display them to the user.
User selects a few of these options, which get sent via POST to php. PHP then grabs the options, which were passed as an an array because of the [], and can easily loop through them and insert them back into db.
If I go with some other characters, say id="option1" instead of id="option[1]", it's no problem on the generation side to loop through and do this of course, but on the processing side, unless I am missing something, I'm left doing something along these lines:
- Get POST data
- Loop through POST array, pattern testing each passed element to see if it starts with 'option'. Store matches in an array of items that do have this pattern
- Foreach this temp array and store the values in the db.
Sound about right?
<input name="option[1]" id="option1" ...
<input name="option[2]" id="option2" ...
<input name="option[3]" id="option3" ...
This way, when the form is submitted, you will still have an "option" array, and on the page each input can be referenced with the id.