Help: Form Data Verification

Welcome. Please Login, Register, Or Activate! 
type your username and password to login
Date: November 25, 2009, 07:30 PM
432622 members and 299547 Topics
Latest Member: Bizman4
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Webmasters (Moderators: OmniPotens, yawa-ti-de)  |  Help: Form Data Verification
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Help: Form Data Verification  (Read 152 views)
greatfiso (m)
Help: Form Data Verification
« on: October 26, 2007, 06:23 PM »

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.");
            history.back();
           </script>   
         <?php 
          exit();  }
         
?>
my2cents (m)
Re: Help: Form Data Verification
« #1 on: October 26, 2007, 07:41 PM »

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,
greatfiso (m)
Re: Help: Form Data Verification
« #2 on: October 27, 2007, 06:28 PM »

 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.
WebMonk (m)
Re: Help: Form Data Verification
« #3 on: October 27, 2007, 07:14 PM »

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)
 Discussions > Adsense Guidelines > On Blog Traffic Exchange Programs   Yoy Need A Script?: Save Time And Make Money  Freeland Marketers Are Wanted  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 


Sections: Autos/Cars (2) Jobs/Vacancies (2) (3) Career Talk Education General(2) Politics Romance Computers Phones Travel
Sports Fashion Health Religion Celebrities TV/Movies (2) Music/Radio (2) Books Webmasters Programming

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa. See also: Nairalist Classified Ads
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.