Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-25-2006, 08:37 AM   #1 (permalink)
transfield
Code Monkey
 
Join Date: Mar 2006
Posts: 35
transfield is on a distinguished road
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.
transfield is offline   Reply With Quote
Old 10-25-2006, 08:49 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,471
sde is on a distinguished road
just iterate and change the string of the post array
PHP Code:
<?php
$bad_data 
= 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-');

for (
$i=1$i<5$i++) {
    if (
in_array(strtoupper($_POST['Text_Box_'.$i]), $bad_data)) {
    
        die(
'This keyword is disallowed. Please click the BACK button of your browser & change your search criteria to something else. Thanks :-)');
    }
}
?>
__________________
Mike
sde is offline   Reply With Quote
Old 10-25-2006, 09:05 AM   #3 (permalink)
transfield
Code Monkey
 
Join Date: Mar 2006
Posts: 35
transfield is on a distinguished road
Excellent help. Thank you Sde. God bless you man :-)
transfield is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Make a search engine for your website with PHP zhisede PHP 3 10-25-2005 07:54 AM
PHP 5.0.4 and 4.3.11 Released sde Code Newbie News 0 04-20-2005 10:56 AM
PHP to Flash control panel roccoman PHP 1 11-24-2004 08:10 AM
PHP vs .NET Redline Lounge 1 11-24-2004 06:10 AM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM


All times are GMT -8. The time now is 03:56 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting