Jump to content

Php Form Validation Issue Using Javascript


lovephp

Recommended Posts

guys im trying to process the validate the once section with javascript and if no error then with php send the confirmation email but even if there is error on the JS validation part the email still gets sent, how to fix it?

 

<?php
session_start();
include ("functions.php");
include ("config.php");
if ( isset($_GET['cid']) ) {
$_SESSION['cid'] = $_GET['cid'];
}
if( $_SESSION['cid'] == ''){
echo '<script type="text/javascript">window.alert("You are not referred from our client!"); </script>';
echo '<p align="center"><font color="red" size="5">Restricted Zone - Don\'t know how you got here!</font></p>';
exit();
}else{

///////error checking part php

if(count($_POST)){ 	
$fData = $_POST;
$error = fCheck($fData);

}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />

<!--[if lte IE 6]>
<meta http-equiv="refresh" content="0;url=error.php" />
<![endif]-->


<script type="text/javascript">
function CheckCC(){

CC_Num = window.document.order.cnumber.value;
// obtaining the type of Credit Card
if (window.document.order.ctype[0].checked == true) {
var CC_Type = window.document.order.ctype[0].value; }
if (window.document.order.ctype[1].checked == true) {
var CC_Type = window.document.order.ctype[1].value; }
if (window.document.order.ctype[2].checked == true) {
var CC_Type = window.document.order.ctype[2].value; }
if (window.document.order.ctype[3].checked == true) {
var CC_Type = window.document.order.ctype[3].value; }
var CCN_digits = "";
for (var i = 0; i < CC_Num.length; i++){
if ((CC_Num.charAt(i) == "0") ||
(CC_Num.charAt(i) == "1") ||
(CC_Num.charAt(i) == "2") ||
(CC_Num.charAt(i) == "3") ||
(CC_Num.charAt(i) == "4") ||
(CC_Num.charAt(i) == "5") ||
(CC_Num.charAt(i) == "6") ||
(CC_Num.charAt(i) == "7") ||
(CC_Num.charAt(i) == "8") ||
(CC_Num.charAt(i) == "9"))
 {
 CCN_digits = CCN_digits + CC_Num.charAt(i); }
}
var validcard = false;
var msgind = 0;

if (CC_Type == "AmericanExpress")
if (CCN_digits.length == 15)
 if ((CCN_digits.substring (0, 2) == "34") ||
 (CCN_digits.substring (0, 2) == "37"))
	 validcard = true;
 else
	 msgind = 1;
else
 msgind = 2;
else if (CC_Type == "Discover")
if (CCN_digits.length == 16)
 if (CCN_digits.substring (0, 4) == "6011")
	 validcard = true;
 else
	 msgind = 1;
else
 msgind = 2;
else if (CC_Type == "MasterCard")
if (CCN_digits.length == 16)
 if ((CCN_digits.substring (0, 2) >= "51") && (CCN_digits.substring (0, 2) <= "55"))
	 validcard = true;
 else
	 msgind = 1;
else
 msgind = 2;
else if (CC_Type == "Visa")
if ((CCN_digits.length == 16) || (CCN_digits.length ==13))
 if (CCN_digits.substring (0, 1) == "4")
	 validcard = true;
 else
	 msgind = 1;
else
 msgind = 2;
else
alert ("Sorry, "+ CC_Type + " is not currently being accepted - please contact us by phone or email.");
if (!validcard){
if (msgind == 1)
 alert ("The Card Number ("+CC_Num + ") and the Card Type (" + CC_Type + ") do not match.");
else if (msgind == 2)
 alert ("The Card Number ("+CC_Num + ") is not the right length for the Card Type (" + CC_Type + ").");
}
if (validcard);
var CheckSum = 0;
for (var x = 1; x <= CCN_digits.length; x++){
var CurrentDigit = CCN_digits.charAt(CCN_digits.length - x);
if (x % 2 == 0) {
 var WorkDigit = CurrentDigit * 2;
 if (WorkDigit > 9) {
	 CheckSum = CheckSum + (1 - 0);
	 CheckSum = CheckSum + (WorkDigit % 10);
 }
 else
 {
	 CheckSum = CheckSum + (WorkDigit - 0);
 }
} else {

 CheckSum = CheckSum + (CurrentDigit - 0);
}
}
if (CheckSum % 10)
{
validcard = false;
alert ("I'm sorry, the Card Number ("+ CC_Num +") is not correct - perhaps there is a typo or two numbers are reversed?");
}
if (validcard);
]////////no error then send email php[/color]
<?php
if(count($error) == 0) {
sendMail($fData);
$url = "order_success.php";
	 header("Location:".$url);
unset($fData);
				 //unset($_SESSION['cid']);
}
?>
}
</script>

Edited by lovephp
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.