I need help with form Errors

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
os17fan
-


Joined: 21 Mar 2003
Posts: 531
Location: USA

PostPosted: Thu Oct 16, 2003 9:33 pm    Post subject: I need help with form Errors Reply with quote

Hey aprelium or someone that knows some PHP

this code will already tell them to change their field that they missed , I want them to go to another page after they filled the form out.

Code:
<?php
if($name){
}else{
echo "Enter your Name <br>";
}
if($email){
}else{
echo "Enter your E-mail <br>";
}
if($site){
}else{
echo "Enter your URL <br>";
}
?>

_________________
This web server is the best !


Last edited by os17fan on Fri Oct 17, 2003 2:06 am; edited 1 time in total
Back to top View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
JohnC
-


Joined: 09 Oct 2003
Posts: 34

PostPosted: Fri Oct 17, 2003 1:14 am    Post subject: Reply with quote

The way you are doing it is a bit crude, you really need to check the FORMAT of the Name/Email/Site.

NAME should check for LENGTH as well, so they at least have to enter more than (say) 3 characters, and not just a dot or a space
EMAIL can checked using Regex - just make sure the syntax is correct. Very hard to actually detect if the addie is valid however !
SITE also can be checked with Regex - if you are even sneakier you could attempt to GET that URL they typed (just get the HEAD) and if it's not OK, show error msg.

I cannot code in PHP, so I'll show you how to do it in "pseudo-PHP/Javascript/Perl" which you'll need to modify to make work... example only :

Code:

function nameTEST(name){
 if(name.length < 3) {return false;}
 return true;
}

// Have one function for each for the 3 tests)

Then have something like this :

var $Message = "";
var $NextPage = "/nextpage.php";
if ( !nameTEST($name) )
  {$Message += "Enter your name"}
if ( !emailTEST($email) )
  {$Message += "Fix/Enter your email"}
if ( !siteTEST($site) )
  {$Message += "Fix/Enter your Site"}

if ($Message) { echo $Message;}
else { echo location = $NextPage; }


This is NOT VALID CODE - just an example of how to deal with it !

The reason for using separate functions for the tests is that it's easier to modify them later, and also you can re-use them in other parts of your script if necessary. If you wanted to use the functions in ANOTHER script, put them in an include file, which you call in at the start of each script - saves a LOT of work and any changes you make only need to be done in ONE place, you don't need to do a search/replace on every script page !

Sorry I can't give you a accurate PHP solution :(

JC
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group