Welcome, Guest: Join Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,869,201 members, 6,886,136 topics. Date: Saturday, 28 May 2022 at 11:15 PM

Help: Form Data Verification - Webmasters - Nairaland

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

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)

(1) (Reply) (Go Down)

Help: Form Data Verification by greatfiso(m): 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(m): 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)

Have You Encountered The Efcc / Can Anyone Design or Develop A Referal Application For A Website? / Ãîëîñîâàíèå! Ïîääåðæèì íàøèõ!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2022 Oluwaseun Osewa. All rights reserved. See How To Advertise. 53
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.