[SOLVED] PHP and form processing, checkboxes...
Posted: Wed Jun 09, 2004 1:30 pm
OK I'm pretty new to PHP and have been working on a form to e-mail script.
It all works fine apart from...
One of the fields on my form is a set of checkboxes.
The checkboxes have the same name name="foo" but each checkbox has a different value.
When I set the variable in my PHP script it just takes one of the values - the last one in the form.
If more than one of the checkboxes is checked, I would like it so that the variable gets all 3 separated by commas.
I know I could call each checkbox a different name, but I'm more curious as to how I would go about doing this.
The way I thought of doing it was by naming each checkbox differently, check1, check2, check3, then concatenating those three variables into another single variable.
I can cope with doing that.
I just wondered if there was another way to do this?
The old form to e-mail script I used to use was written in Perl, and when I set a checkbox field, with multiple options all with the same input name, the output came through as comma separated list of values.
Is the comma separated thing I saw in the results of the old Perl script something to do with the way data is transmitted via method=post
Or was it done using special scripting in Perl?
Would the solution I outlined above be the best way to solve this problem?
Could the data be parsed to an array of some kind when it is processed?
Doing something like, if a field name appears more than once, then put successive values into an array?
I'd be interested to hear your opinions.
Thanks
It all works fine apart from...
One of the fields on my form is a set of checkboxes.
The checkboxes have the same name name="foo" but each checkbox has a different value.
When I set the variable in my PHP script it just takes one of the values - the last one in the form.
If more than one of the checkboxes is checked, I would like it so that the variable gets all 3 separated by commas.
I know I could call each checkbox a different name, but I'm more curious as to how I would go about doing this.
The way I thought of doing it was by naming each checkbox differently, check1, check2, check3, then concatenating those three variables into another single variable.
I can cope with doing that.
I just wondered if there was another way to do this?
The old form to e-mail script I used to use was written in Perl, and when I set a checkbox field, with multiple options all with the same input name, the output came through as comma separated list of values.
Is the comma separated thing I saw in the results of the old Perl script something to do with the way data is transmitted via method=post
Or was it done using special scripting in Perl?
Would the solution I outlined above be the best way to solve this problem?
Could the data be parsed to an array of some kind when it is processed?
Doing something like, if a field name appears more than once, then put successive values into an array?
I'd be interested to hear your opinions.
Thanks