This is a discussion on "[SOLVED] Form Checkbox Validation" within the PHP Forum section. This forum, and the thread "[SOLVED] Form Checkbox Validation are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
[SOLVED] Form Checkbox Validation
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
[SOLVED] Form Checkbox Validation
Hey guys,
I have a form on my website that contains three checkboxes. One of the checkboxes is called "other" and has a text field next to it where the user specifies other. Here is a visual:
I have this so far:
Any suggestions? Thanks, SWagner
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
|
|
#2
|
||||
|
||||
|
Re: Form Checkbox Validation
You nearly got it you just have to say AND instead of OR
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
#3
|
|||
|
|||
|
Re: Form Checkbox Validation
Thanks! I had that in the back of my head, I just didn't remember it at the time...
Now, I also have a bit of an opinion question: What should I say for the error (the one in my script is just an example)? I remember a thread by Alex about client-personnel etiquette and I wondered how I would phrase a friendly pointer to fill in the textbox if the checkbox is checked. I have this: You have selected "Other". Please specify But I don't like it since I use quotes for the name of the checkbox. Maybe something like "You have selected other but you forgot to fill in the specification." Any suggestions?
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
#4
|
||||
|
||||
|
Re: Form Checkbox Validation
It depends on the context of the form really.. If it's a professional site something like
"Please specify what shoes you wear" or whatever the actual form is for... Also try to make sure it is obvious that they have to add something -- change the background colour of the text box when they choose that checkbox for example... Most polite explanations are fine just don't say something like "You silly nong, I can't believe you forgot to specify something -- perhapds you should go back to school for a while and then come and try out this form" --- that may intimidate some people
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
#5
|
|||
|
|||
|
Re: Form Checkbox Validation
i kinda like this phrase :]
error - pleae fill in the Other text |
|
#6
|
|||
|
|||
|
Re: Form Checkbox Validation
Thanks for the suggestions.
Quote:
No error Label: [textbox] Error Label: [textbox] That will make it obvious to the user what field contains the error.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Nov 10th, 2007 at 19:53. |
|
#7
|
|||
|
|||
|
Re: Form Checkbox Validation
OK. Hold on... How do I make the php do what I mentioned in that last post? Do I have to generate the content from the beginning on? So, php echo the form? I have no clue... I've never done something like this before! Don't get frustrated with me...
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
#8
|
|||
|
|||
|
Re: Form Checkbox Validation
I have done this....gimme a while and i'll dig out the code
|
|
#9
|
|||
|
|||
|
Re: Form Checkbox Validation
Right...you need to do some sort of validation checking for empty fields etc
check if the field is empty....or wahetever you want
|
|
#10
|
|||
|
|||
|
Re: Form Checkbox Validation
Hmm, doesn't seem to work for me... Take a look at my form: (* denotes a required field)
Edit: Added asterisks to show required fields.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Nov 10th, 2007 at 17:43. |
|
#11
|
|||
|
|||
|
Re: Form Checkbox Validation
you need to check the validation and if it fails redisplay the form
|
|
#12
|
|||
|
|||
|
Re: Form Checkbox Validation
Quote:
What i have done with my form is change th ecolor of the input fields but if you have checkboxes that need validating, you're better off doing the label. If you let me know what needs to be validated, i'll have a go at your form for you |
|
#13
|
|||
|
|||
|
Re: Form Checkbox Validation
Well, just as a side info, the form's purpose is a webmaster contact form. It allows users to contact me (the webmaster) through a form. They can report a problem, comment on something, ask a question, or make a suggestion by choosing a radio button. So, that part is required. The email field is also required, as well as the message field. I put asterisks into my code above to show which fields are required and should change color.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
#14
|
|||
|
|||
|
Re: Form Checkbox Validation
So you want the email, message and if they have selected problem and not ticked any boxes
|
|
#15
|
|||
|
|||
|
Re: Form Checkbox Validation
Yup. Actually, why don't I just give you the link to the actual page (webmaster.php) where php validation already works through an external file (webmaster.process.php). Go there
Maybe that will clear things up.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
#16
|
||||
|
||||
|
Re: Form Checkbox Validation
You're on a different page when you're validating so you'll have to use the $_SESSION
In the validting php script place <?php session_start(); ?> At the very top and then for each field that is required and doesn't validat do something like
When you get into the form do something like
This is how you can do it because your form isn't recursive, it is being processed by a different script. Hope that helps,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|