₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,225 members, 8,510,775 topics. Date: Saturday, 31 October 2026 at 03:19 AM

Toggle theme

Help: Form Data Verification - Webmasters - Nairaland

Nairaland Forum › Science/Technology › Webmasters › Help: Form Data Verification (867 Views)

1 Reply (Go Down)

Help: Form Data Verification by greatfiso(op): 6:23pm On Oct 26, 2007
Hope u all had a grt day?
for me, i've been battling this code below all day.
pls i need help on how to verify data from my HTML form


the problem i have with the code below is that it keeps giving me
the error message when the field (which is not required) is empty.
pls a messiah should come to my aid.

<?php
// TO CHECK THE DATA COMING IN
$pattern = '([[:digit:]]|[~`!@$%&()_ =+|\:;"/?,]|[|]|-)+';
$name = stripslashes($_POST['ady2']);
if (ereg($pattern,$_POST['ady2']))
{?><SCRIPT language=javascript>

alert("Characters such as > * # \" Are NOT Accaptable."wink;
history.back();
</script>
<?php
exit(); }

?>
Re: Help: Form Data Verification by my2cents(m): 7:41pm On Oct 26, 2007
Apparently, there is something in your regex, otherwise you wouldn't be getting this error. I would do an alert of the value of the (assuming) text field and go from there. Perhaps you should apply trim() to the $name field first b4 stripslashes(), to remove any trailing spaces?

In general, I don't like mixing javascript with code, at least the way you are doing it. I would clean this up by doing a regex check on the javascript side, moving that code into a .js file, then of course having the php code do a 2ble-check in case the user has javascript turned off. The way you have it here, the implication is that you will have "<script>" tags printed out for each form field you have. If this is the case, not good.

Try what I have suggested in the first paragraph above and let us know if that works or not.

Thanks,
Re: Help: Form Data Verification by greatfiso(op): 6:28pm On Oct 27, 2007
thank you
your post was more than helpful
the problem was locked around the regex and the $name
got it sorted.
thank u 4 d javascript comment too.
Re: Help: Form Data Verification by WebMonk(m): 7:14pm On Oct 27, 2007
it's been a long, long, time since i held 2 pieces of code with a pair of tweezers in one hand and a magnifiying glass in the other (my2cents, you also did javascript? what DIDN'T YOU DO!!?)

@ poster: if you're using Dreamweaver, then all that is a snap. there's and extensive dreamweaver extension that does just that: form validation. with custom messages. it's here:

http://www.yaromat.com/dw/?ex=Check%20Form%20MX

(remembers the good OLD Days of coding in ASP, then shrugs from the nightmares)
1 Reply

How To Get Facebook Page And Twitter Verification For Nigerian Businesses. • Paypal Phone Verification Services • Usa Phone Verification Services With Text Sms • 2 • 3 • 4

Web Design Question • Amazing Site, Join For Free, Socialize And Get Paid For Doin Dat • Check This Out