p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Validation


Message #1 by "Fakhouri, Nathan" <NFakhouri@t...> on Wed, 2 Jan 2002 11:37:05 -0500
Hello,



If you click the submit button, I have php code that checks each field to

see if they have been completed or not.  



like this:



---------------------------



$PassFail = 1;



if ($mpv1 == ""){ //name of field

    echo("You failed to select a field from Mistake Proofing Verification.

<br>"); //message to be displayed if the field is left empty

    $PassFail = 0;	//if field is empty, $PassFail takes value 0

} 

}



ect.. ect.. 



if ($PassFail == 1){

include the rest of my program

}

else

{

please click the back button in your browser and make the appropriate

changes

}



---------------------------------



This test does not work if the entered value is a single space.  



There must be a better way to accomplish this.  Please Help!!! 



Thanks,



~Nathan 

~nfakhouri@t...

Message #2 by "Peter Simard" <peter@p...> on Wed, 02 Jan 2002 14:28:39 -0500
Personally I do my validation client side with JavaScript, preferring to

 take that burden off the server.  If my user has their JavaScript turned

 off...too bad for them, they can turn it back on.



If you really want to do server side validation, before you validate the

 entry, use the trim() function to remove trailing and beginning

 whitespace, that should also make a single whitespace entry into a blank

 field, which you have validation for.



HTH



Pete



*********** REPLY SEPARATOR  ***********



On 1/2/2002 at 11:37 AM Fakhouri, Nathan wrote:



>Hello,

>

>If you click the submit button, I have php code that checks each field to

>see if they have been completed or not.  

>

>like this:

>

>---------------------------

>

>$PassFail =3D 1;

>

>if ($mpv1 =3D=3D ""){ //name of field

>    echo("You failed to select a field from Mistake Proofing Verification.

><br>"); //message to be displayed if the field is left empty

>    $PassFail =3D 0;	//if field is empty, $PassFail takes value 0

>} 

>}

>

>ect.. ect.. 

>

>if ($PassFail =3D=3D 1){

>include the rest of my program

>}

>else

>{

>please click the back button in your browser and make the appropriate

>changes

>}

>

>---------------------------------

>

>This test does not work if the entered value is a single space.  

>

>There must be a better way to accomplish this.  Please Help!!! 

>

>Thanks,

>

>~Nathan 

>~nfakhouri@t...

>




 $subst('Email.Unsub').







Message #3 by "Nikolai Devereaux" <yomama@u...> on Wed, 2 Jan 2002 13:29:06 -0800



I also agree that you should do as much validation on the client side with

Javascript as possible.



That said, chances are you're expecting some specific sort of input.  If

you're expecting a phone number, you shouldn't accept any letters, etc.



Use regular expressions to make sure that whatever was entered matches what

you expect.





While we're on the subject, I'd recommend a couple things (from a purely

annoyed-at-crappy-forms-user standpoint):



1.  save ALL the form data that was submitted that was fine and dandy and

repopulate the fields of your form with that data so the user doesn't have

to retype it.  I hate that, and usually won't ever completely re-fill out a

form when only one of my fields was bad to begin with.  Sometimes clicking

"back" doesn't fix this.



2.  Validate ALL fields in one sweep, regardless of failures.  I hate it

when I fill out a form and I get the error message that one field was wrong.

So I fix that, and then I get another error message that some other field

was wrong.  Just tell me all the things you think are wrong, and I'll fix

them all in one sweep.





good luck,



nk



-----Original Message-----

From: Fakhouri, Nathan [mailto:NFakhouri@t...]

Sent: Wednesday, January 02, 2002 8:37 AM

To: beginning php

Subject: [beginning_php] Validation





Hello,



If you click the submit button, I have php code that checks each field to

see if they have been completed or not.



like this:



---------------------------



$PassFail = 1;



if ($mpv1 == ""){ //name of field

    echo("You failed to select a field from Mistake Proofing Verification.

<br>"); //message to be displayed if the field is left empty

    $PassFail = 0;	//if field is empty, $PassFail takes value 0

}

}



ect.. ect..



if ($PassFail == 1){

include the rest of my program

}

else

{

please click the back button in your browser and make the appropriate

changes

}



---------------------------------



This test does not work if the entered value is a single space.



There must be a better way to accomplish this.  Please Help!!!



Thanks,



~Nathan

~nfakhouri@t...






$subst('Email.Unsub').




  Return to Index