I have a pretty basic form here:
I am using a js function to validate the fields. I have a php statement to check and see if the submit button has been pressed:
Here's the problem: when you click "Sign Me Up" ($submit), the js function does work, however, after you click "ok" the form is posted anyway without giving the user the chance to make corrections.
I know the problem is with the php statement "if ($submit)--process form" so I've tried changing the condition of the if statement but have had no success.
Here is the js:
and the php if statement:
Thanks in advance for any help.
I am using a js function to validate the fields. I have a php statement to check and see if the submit button has been pressed:
Code:
if ($submit) {
//process form
Here's the problem: when you click "Sign Me Up" ($submit), the js function does work, however, after you click "ok" the form is posted anyway without giving the user the chance to make corrections.
I know the problem is with the php statement "if ($submit)--process form" so I've tried changing the condition of the if statement but have had no success.
Here is the js:
Code:
<script language="JavaScript">
function IsFormComplete(FormName) {
var x = 0
var FormOk = true
while ((x < document.forms[FormName].elements.length) && (FormOk)) {
if (document.forms[FormName].elements[x].value == '') {
alert('Please enter the '+document.forms[FormName].elements[x].name +' and try again.')
document.forms[FormName].elements[x].focus()
FormOk = false
}
x ++
}
return FormOk
}
and the php if statement:
Code:
<?php
if ($submit) {
//process form
$db = @mysql_connect ('123.123.123.123', 'username', 'password') or
die("Couldn't connect to localhost database with username: username");
$db_selected = @mysql_select_db ('table', $db) or
die("Couldn't hook into database: table");
$sql = "INSERT INTO table(event, email, fname, lname, address, city, state, zip, country, phone, referral, guest_email, guest_fname, guest_lname, guest_address, guest_city, guest_state, guest_zip, guest_country, guest_phone, cc_number, cc_expiration, ccv_number, cc_name, guest_cc_number, guest_cc_expiration, guest_ccv_number, guest_cc_name) VALUES ('$event', '$email', '$fname', '$lname', '$address', '$city', '$state', '$zip', '$country', '$phone', '$referral', '$guest_email', '$guest_fname', '$guest_lname', '$guest_address', '$guest_city', '$guest_state', '$guest_zip', '$guest_country', '$guest_phone', '$cc_number', '$cc_expiration', '$ccv_number', '$cc_name', '$guest_cc_number', '$guest_cc_expiration', '$guest_ccv_number', '$guest_cc_name')";
$results = @mysql_query ($sql) or
die('Statement failed: ' . $sql);
} else {
//display form
?>
Thanks in advance for any help.