Log in

View Full Version : need to restricting forms submits based on data



ChrisVersion2
01-16-2008, 06:04 PM
I have a form located here https://www.lgw.com/dev/sampleformcard.htm

and I'd like to stop people from submitting the form if there credit card starts with several different combination of 4 numbers.

The list is very long (almost 300 different combo) and I was looking for suggestions on how I could accomplish this.

My first thought was it break up the one field into 4 fields, (like the four groups of numbers on your credit card) and just run the filter on the first field.

what programming language would I use? maybe PHP and run it against a CSV file?

Any direction would be helpful.


Regards,
Chris

Jas
01-16-2008, 07:41 PM
PHP would do great, and you would not have to break it up into four feilds-- just use the preg_split functions to grab the first four numbers. You could also store the numbers in a MySQL database and retrive them that way, as opposed to the CSV, but whatever way you like. :)

ChrisVersion2
01-16-2008, 08:06 PM
I have no experience in mySQL, but PHP might be the way to go, any chance you could show a sample, and/or point me to a sample?


:o thanks

Jas
01-17-2008, 05:14 PM
I threw this together really quick, but hopefully it works.

<?php

//check to see if the form has been set
if(isset($_POST['submit'])){
#CONNECT TO MYSQL HERE
//get first 4 numbers
$credit = preg_split("/[\D{5}]/",$_POST['number']);
//look in mysql for the numbers
$rows = MySQL_query("SELECT * FROM table WHERE number = \"".$credit[0]."\"");
//see if there was at least one match
if(MySQL_num_rows($rows) <= 1){\
die('FOUND A MATCH FOR THE CREDIT CARD NUMBER');
}else{
//process the info
}

}else{
echo "<form action='".$_SERVER['PHP_SELF']."' method='POST'>
<input type='text' name='number'>
<input type='submit' name='submit' value='submit'>
</form>";
}

?>