Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: PHP Validation

  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Validation

    Hello,
    I want to validate 4 text boxes(in a html form) to prevent users from keying in certain words. I'm using the code below to validate 1 text box & the code works fine. How do I use the same code to validate all 4 text boxes instead of re-writing the code 4 times?

    My code:-
    PHP Code:
    if (in_array(strtoupper($_POST['Text_Box_1']), array('03-''04-''05-''06-''07-''08-''09-''012''013''016''017''019''E10''E20''E30''RM1''RM2''RM3''RM4''RM5''RM6''RM7''RM8''RM9''012-''013-''016-''017-''019-'))) die('This keyword is disallowed. Please click the BACK button of your browser & change your search criteria to something else. Thanks :-)'); 
    The names of my text boxes are:-
    Text_Box_1
    Text_Box_2
    Text_Box_3
    Text_Box_4

    Thanks a lot for your assistance.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    try
    PHP Code:
    if (in_array(strtoupper($_POST['Text_Box_1'], $_POST['Text_Box_2'), array('03-''04-''05-''06-''07-''08-''09-''012''013''016''017''019''E10''E20''E30''RM1''RM2''RM3''RM4''RM5''RM6''RM7''RM8''RM9''012-''013-''016-''017-''019-'))) die('This keyword is disallowed. Please click the BACK button of your browser & change your search criteria to something else. Thanks :-)'); 
    and comma seperate the box names like i did


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •