PHP Form Validation |
PHP Form Validation |
dougmanic |
Nov 25 2006, 10:00 PM
Post
#1
|
Newbie Group: Members Posts: 19 Joined: 3-October 06 Member No.: 320 |
I'm trying to validate a form using PHP, so that if a user enters a empty value in any of the fields (I have text boxes, drop-down options and radio buttons), data will not be submitted and a red error text will appear above the field.
I tried creating a function that will check if each of the required fields are entered. If they are, data will be saved; if not the form will be printed again with the error. But the problem here is that all the input that the user entered disappears and all the options are unselected. Is there anyway else to do this? This post has been edited by dougmanic: Nov 25 2006, 10:00 PM |
Brian Chandler |
Nov 26 2006, 05:23 AM
Post
#2
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
I'm trying to validate a form using PHP, so that if a user enters a empty value in any of the fields (I have text boxes, drop-down options and radio buttons), data will not be submitted and a red error text will appear above the field. This won't work. PHP runs on your server, so unless stuff is *submitted* your PHP program will never see it. QUOTE I tried creating a function that will check if each of the required fields are entered. If they are, data will be saved; if not the form will be printed again with the error. But the problem here is that all the input that the user entered disappears and all the options are unselected. Is there anyway else to do this? Unless you show us this function, it's hard to comment on. But what you ought to be doing is to write a javascript 'onsubmit' handler, that checks fields are completed, and refuses to submit if they aren't. (Then, of course, the form handler needs to check the submitted data, and respond appropriately if it's no good.) |
Darin McGrew |
Nov 26 2006, 12:21 PM
Post
#3
|
WDG Member Group: Root Admin Posts: 8,365 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 |
Please see the FAQ entry How can I require that fields be filled in, or filled in correctly?
|
Curtis |
Dec 28 2006, 04:49 AM
Post
#4
|
Newbie Group: Members Posts: 11 Joined: 28-December 06 From: California Member No.: 1,397 |
Wow, it's been a while since I've been here - new forums are looking great!
If you want the front end control that JS allows, plus the power of your server side scripting, asynchronous scripting (Ajax) is an option. If you're new to this topic, you should be aware of the host of accessibility problems posed by using Ajax, though. |
Lo-Fi Version | Time is now: 28th March 2024 - 02:29 PM |