The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> PHP Form Validation
dougmanic
post 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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Nov 26 2006, 05:23 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE(dougmanic @ Nov 26 2006, 12:00 PM) *

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.)


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post 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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Curtis
post 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! biggrin.gif

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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 02:29 PM