Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
form feild validation not working
Old 10-05-2007, 02:11 AM form feild validation not working
Average Talker

Posts: 18
Name: sorocco
Trades: 0
hi ,
I followed a procedure from a website to create a form ..but the validation is not working ..it ignores to check the required feild and just sends the confirmation mail ..what could be the reason ?....pls help..my code :

<?

session_start();
function checkOK($field)
{
if (eregi("\r",$field) || eregi("\n",$field)){
die("Invalid Input!");
}
}

$name=$_POST['name'];
checkOK($name);
$email=$_POST['email'];
checkOK($email);
$telephone=$_POST['telephone'];
checkOK($telephone);
$address=$_POST['address'];
checkOK($address);
$comments=$_POST['comments'];
checkOK($comments);
$to="userid@domain.name";
$message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email and telephone:$telephone with Address as:$address";
if(mail($to,"Comments From Your Site",$message,"From: $email\n")) {
echo "Thanks. your request has been received.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>


thanks
soroccoheaven is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-05-2007, 01:21 PM Re: form feild validation not working
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Putting an IF function around the checkOK() parts would be a good idea. The do an analysis of what's exactly wrong.

** reads code **

It could also be that, all your checking for is line breaks. Which tends to appear a lot anyway, and also does no harm.

PHP Code:
<?

session_start
();
function 
checkOK($field)
{
if (
eregi("\r",$field) == TRUE || eregi("\n",$field) == TRUE){
die(
"Invalid Input!");
}
}

$name=$_POST['name'];
checkOK($name);
$email=$_POST['email'];
checkOK($email);
$telephone=$_POST['telephone'];
checkOK($telephone);
$address=$_POST['address'];
checkOK($address);
$comments=$_POST['comments'];
checkOK($comments);
$to="userid@domain.name";
$message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email and telephone:$telephone with Address as:$address";
if(
mail($to,"Comments From Your Site",$message,"From: $email\n")) {
echo 
"Thanks. your request has been received.";
} else {
echo 
"There was a problem sending the mail. Please check that you filled in the form correctly.";
}
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 10-05-2007 at 01:22 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 10-05-2007, 03:27 PM Re: form feild validation not working
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
I would put an echo() or something in the checkOK function: it might actually be getting called, unless you know otherwise of course. If it is, your eregi just doesn't work.
__________________
Foundation Flash tutorials :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 10-06-2007, 02:45 PM Re: form feild validation not working
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Sorry i dont quite get why you are doing the eregi on \r and \n whats the purpose?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-06-2007, 10:52 PM Re: form feild validation not working
Average Talker

Posts: 22
Name: Paul
Trades: 0
Why don't you use this approach?

PHP Code:
if ($name == ""){
?><font color="#ffffff">You must enter your name</font><?php
}
This works for me. If the name is not entered, the script stops, and no email is sent. Apart from that, the script will halt and will not go any further until the user corrects the issue.
__________________
Free Web Hosting Available At Simply Web Host

Please login or register to view this content. Registration is FREE
smithster is offline
Reply With Quote
View Public Profile Visit smithster's homepage!
 
Old 10-07-2007, 06:42 AM Re: form feild validation not working
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
EEEWW <font> tag Ew bad paul..
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-07-2007, 08:41 AM Re: form feild validation not working
Average Talker

Posts: 22
Name: Paul
Trades: 0
lol, I don't even use that way anymore!! I was tired last night and I was already rewriting a script that had that in. My bad!!

PHP Code:
if ($name == ""){
echo 
"You must enter your name";


I used to do it that way when I didn't understand how to put font colours and sizes and stuff like that into PHP. Now I do.

PHP Code:
if ($name == ""){
echo 
"<font color=\"#ffffff\">You must enter your name</font>" ."";

__________________
Free Web Hosting Available At Simply Web Host

Please login or register to view this content. Registration is FREE
smithster is offline
Reply With Quote
View Public Profile Visit smithster's homepage!
 
Old 10-07-2007, 11:48 AM Re: form feild validation not working
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Doublw EEw YOUR STIlL USING <font> TAG!! XD EEEW
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-07-2007, 11:59 AM Re: form feild validation not working
joder's Avatar
Flipotron

Posts: 6,442
Name: James
Location: In the ocean.
Trades: 0
OMG the font tag AHHHHH! Use CSS
joder is offline
Reply With Quote
View Public Profile
 
Old 10-07-2007, 12:17 PM Re: form feild validation not working
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Run AWAY!.....

- not that i am obsessed with Monty Python or anything.. You know having a quote for all occasions..
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-07-2007, 01:35 PM Re: form feild validation not working
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Umm , lovely

Back on topic - If your going to do server side validation then you might as well cover all bases. Email injection is painful http://www.tonyspencer.com/2005/12/1...-contact-form/
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 10-07-2007, 01:49 PM Re: form feild validation not working
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
That is SO FREAKKY!

i was making a script today and was ticking off all the security i had (and needed to add) and was thinking should i add any security to the email ?

i never seen anything about it interesting...

Would the mysql_real_escape_string() work to stop this as well as SQL injection?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-07-2007, 03:12 PM Re: form feild validation not working
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
There are other ways of protecting from mail injection, ie. CAPTCHAs and a new technique using a form element way off the side of the screen tha tonly a bot would fill in.
__________________
Foundation Flash tutorials :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 10-07-2007, 03:16 PM Re: form feild validation not working
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
?


or... just use CSS to make it the same as your background... (which i did when i made a proxy for my school it was a clone of the school website andthe field was hidden in the page
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to form feild validation not working
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.73171 seconds with 12 queries