filter question - php Form

Author Topic: filter question  (Read 1467 times)

Offline henry

  • Supporter
  • **
  • Posts: 3
  • Karma: +0/-0
    • View Profile
filter question
« on: February 19, 2010, 03:23:55 PM »


Hey all !

New here just found this forum....

Question....

I have a form which get a lot of junk viagra links...


can someone help me with; requiring all fields be filled ( to allow submission )
and check to see that "PHONE" field has 10 and only 10 digits.

I will see if that curbs the junk, if not I may use some verification code.

I am new to this and have learned PHP by "destructive Testing"  ;)

Thanks

Offline elwir

  • Supporter
  • **
  • Posts: 2
  • Karma: +1/-0
    • View Profile
Re: filter question
« Reply #1 on: February 19, 2010, 04:28:52 PM »
Code: [Select]
<?php
if(isset($_POST['submit']))
{
$name $_POST['name'];
$tel $_POST['tel'];
if (
strlen($tel) <> 10) {
echo 
'Phone number must have exactly 10 digits:<a href="javascript:history.go(-1)"> go back</a>';  
exit();
}
if (
ereg("\viagra"$name)) {
echo 
'The word ' $name ' is not allowed:<a href="javascript:history.go(-1)"> go back</a>';  
exit();
}
echo 
"true";
}else{
?>

<form action="index.php" method="POST">
Text
<input type=text name="name"><br>
Tel.
<input type=text name="tel"><br>
<input type="submit" name="submit">
</form>
<?php
}
?>


Offline henry

  • Supporter
  • **
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: filter question
« Reply #2 on: February 27, 2010, 08:14:50 AM »
Hey! Thanks Elwir

I have just checked in and have yet to implement .

The 'strlen'  is self-explanatory, but what is 'ereg' stand for?.................
Can .........
}
if (ereg("\viagra", $name)) {

 expanded to ?

}
if (ereg("\viagra, pills, rolex", $name)) { 

Thanks
Henry

Offline henry

  • Supporter
  • **
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: filter question
« Reply #3 on: March 04, 2010, 09:17:26 AM »
Thanks, works perfect, I just changed error output to "phone error" don't want to tell spammers how many digits I am looking for.


if (strlen($tel) <> 10)

Next to filter postal code must be "alpha, num, alpha, num, alpha, num" eg b2c3d4