Search engine optimization forum
Search engine optimization forum
Making websites work.
You are not logged in.
#1 2006-11-11 09:43:46
- Pathfinder365
- SEO n00b
- Registered: 2006-11-11
- Posts: 7
- Website
PHP coding for use with form checkboxes
Hi
I am trying to set up a feedback form on my site for my website visitors which uses php and XHTML, I am not a web designer and will admit that I as yet do not fully understand php, but I have managed to set up a form and get the radio button option to work without problem using the following code
<tr>
<td>How did you hear about us?</td>
<td>
<input type="radio" name="referral" value="Search Engine" checked="checked" /> Search Engine<br />
<input type="radio" name="referral" value="Another Web Site" <?php if($_POST['referral'] == 'Another Web Site') echo 'checked="checked"'; ?> /> Another Web Site<br />
<input type="radio" name="referral" value="Friend" <?php if($_POST['referral'] == 'Friend') echo 'checked="checked"'; ?> /> Friend<br />
</td>
</tr>
However I also what to give multiple choices to my website visitors using a checkbox so I added this code
<tr>
<td>Which areas of our web site have you visited?<br />
(Select all that apply)</td>
<td>
<input type="checkbox" name="visit" value="Free Demos" <?php if($_POST['visit'] == 'Free Demos') echo 'checked="checked"'; ?> /> Free Demos<br />
<input type="checkbox" name="visit" value="Course Details" <?php if($_POST['visit'] == 'Course Details') echo 'checked="checked"'; ?> /> Course Details<br />
<input type="checkbox" name="visit" value="IT News" <?php if($_POST['visit'] == 'IT News') echo 'checked="checked"'; ?> /> IT News<br />
<input type="checkbox" name="visit" value="Forum" <?php if($_POST['visit'] == 'Forum') echo 'checked="checked"'; ?> /> Forum
</td>
</tr>
Although the checkbox is displayed correctly and I can select multiple options, when I submit the form I only receive one of the checked options.
I know this problem must be to do with my php code, any ideas where I have gone wrong?
Any help greatly appreciated
Last edited by Pathfinder365 (2006-11-11 09:53:41)
Offline
#2 2006-11-11 11:25:44
Re: PHP coding for use with form checkboxes
A quick look at that seems to suggest that the checkbox names need to be unique. If multiple form elements are named the same, only the last value gets sent so regardless of the choices selected in the other fields, only one result gets posted to the PHP.
Edward Clarke - eCommerce Consultant
Work: ebizcentre.co.uk
Blog: blog.tn38.net
F1 Gallery: formula1photos.tn38.net
Offline
#3 2006-11-11 12:18:31
- Pathfinder365
- SEO n00b
- Registered: 2006-11-11
- Posts: 7
- Website
Re: PHP coding for use with form checkboxes
Thanks Edward
I thought the problem was not using the id= option, I have changed the code to use different names and this appears to be working except for the reset option
Many thanks
Offline