Click to See Complete Forum and Search --> : Pyro.. help?


Jonathan
07-15-2003, 02:11 AM
What is wrong with this script, it doesn't return false

<script language="JavaScript" type="text/javascript">
<!--
function checkform()
{
if (document.front.Name.value=="" || document.front.Reason.value=="")
{
alert("The information you have entered is either invalid or blank.");
document.front.Name.focus();return false
}

if (document.front.Name.value!="" || document.front.Name.value!="Last, First")
{if (document.front.Name.value.indexOf(" ")!=-1 || document.front.Name.value.indexOf(",")!=-1 || document.front.Name.value.indexOf("!")==-1 || document.front.Name.value.indexOf("@")==-1 || document.front.Name.value.indexOf("#")==-1 || document.front.Name.value.indexOf("$")==-1 || document.front.Name.value.indexOf("%")==-1 || document.front.Name.value.indexOf("^")==-1 || document.front.Name.value.indexOf("&")==-1 || document.front.Name.value.indexOf("*")==-1 || document.front.Name.value.indexOf("(")==-1 || document.front.Name.value.indexOf(")")==-1)
{alert("Your name should be in this format\: Last, First");
document.front.Name.focus();return false}
}

}
//-->
</script>

pyro
07-15-2003, 07:37 AM
You can shorten it quite a bit (and make it work) by using regexp:

<script language="JavaScript" type="text/javascript">
function checkform() {
if (document.front.Name.value=="" || document.front.Reason.value=="")
{
alert("The information you have entered is either invalid or blank.");
document.front.Name.focus();
return false;
}
if (!/\w, \w/.test(document.front.Name.value)) {
alert("Your name should be in this format\: Last, First");
document.front.Name.focus();
return false
//}
}
}
</script>

Jonathan
07-15-2003, 10:18 AM
Here is everything... my PHP code, and my file.

HTML file:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>Events</TITLE>
<LINK REL="stylesheet" href="all.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<META NAME="keywords" CONTENT="">
<META NAME="description" CONTENT="">
<META NAME="author" CONTENT="Jonathan">

<script language="javascript" type="text/javascript">
<!--
Image1 = new Image(500,25)
Image1.src = "thsearching.jpg"
-->
</script>

<script language="JavaScript" type="text/javascript">
function checkform() {
if (document.front.Name.value=="" || document.front.Name.value=="Last, First" || document.front.Reason.value=="" || document.front.Reason.value=="Explain here")
{
alert("The information you have entered is either invalid or blank.");
document.front.Name.focus();
return false;
}
if (!/\w, \w/.test(document.front.Name.value)) {
alert("Your name should be in this format\: Last, First");
document.front.Name.focus();
return false
//}
}
if (document.front.Email.value!="" || document.front.Email.value!="you@domain.com")
{
if (document.front.Email.value.indexOf("@")==-1 || document.front.Email.value.indexOf(".")==-1 || document.front.Email.value.indexOf(" ")!=-1 || document.front.Email.value.length<6)
{alert("Your e-mail address is not valid, it must be in the following format: you@domain.com");
document.front.Email.focus();return false}
}
}
</script>

<script language="JavaScript" type="text/javascript">
function checkform() {
if (document.reserving.Name.value=="" || document.reserving.Name.value=="Last, First" || document.reserving.Number.value=="" || document.reserving.Number.value=="Number of People")
{
alert("The information you have entered is either invalid or blank.");
document.front.Name.focus();
return false;
}
if (!/\w, \w/.test(document.front.Name.value)) {
alert("Your name should be in this format\: Last, First");
document.front.Name.focus();
return false
//}
}
if (document.reserving.Email.value!="" || document.front.Email.value!="you@domain.com")
{
if (document.front.Email.value.indexOf("@")==-1 || document.front.Email.value.indexOf(".")==-1 || document.front.Email.value.indexOf(" ")!=-1 || document.front.Email.value.length<6)
{alert("Your e-mail address is not valid, it must be in the following format: you@domain.com");
document.front.Email.focus();return false}
}
}
</script>
</HEAD>

<BODY>
<form method="post" name="front" action="searching.php" onsubmit="checkform()">
<table border="0" summary="Crosspoint's Searching">
<th><img src="thsearching.jpg" alt="Crosspoint's Searching" border="0"></th>
<tr>
<td class="event">If you would like to be baptized on our 5<sup>th</sup> annual Church on the Lake fellowship please enter the following information:</td>
</tr>
</table>
<table>
<tr>
<td>Name:</td>
<td><input type="text" class="text" name="Name" value="Last, First" maxlength="50" onfocus="this.value=''"></td>
</tr>
<tr>
<td>Reason:</td>
<td><input type="text" class="text" name="Reason" value="Explain here" maxlength="50" onfocus="this.value=''"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" class="text" name="Email" value="you@domain.com" maxlength="50" onfocus="this.value=''"></td>
</tr>
<tr>
<td><input type="submit" value="Submit">
<td>&nbsp;</td>
</tr>
</table>
</form>
<br>

<form method="post" name="reserving" action="reservation.php" onsubmit="checkdata()">
<table border="0" summary="Reserving">
<th><img src="reservation.jpg" alt="Reserving Spots" border="0"></th>
<tr>
<td class="event">If you would like to reserve a camping spot for <b>Church on the Lake</b> then please
fill out the following information:<br></td>
</tr>
</table>
<table>
<tr>
<td>Name:</td>
<td><input type="text" class="text" name="Name" value="Last, First" maxlength="50" onfocus="this.value=''"></td>
</tr>
<tr>
<td>Number:</td>
<td><input type="text" class="text" name="Number" value="Number of People" maxlength="50" onfocus="this.value=''"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" class="text" name="Email" value="you@domain.com" maxlength="50" onfocus="this.value=''"></td>
</tr>
<tr>
<td><input type="submit" value="Submit">
<td>&nbsp;</td>
</tr>
</table>
</form>
<br>
<h3>Events</h3>
<table>
<tr>
<td align=left style="background-color:#1D2C7F; color:white;" class="event"> Title </td>
<td align=left style="background-color:#1D2C7F; color:white;" class="event"> Location </td>
<td align=left style="background-color:#1D2C7F; color:white;" class="event"> Date </td>
</tr>
<tr>
<td align=left class="event"><a href="http://www.worldchangers.org/"> Youth Mission Trip Begins </a></td>
<td align=left class="event"> Bremmerton, WA </td>
<td align=left class="event"> July 18 </td>
</tr>
<tr>
<td align=left class="event">Church on the Lake</td>
<td align=left class="event">Frenchmen’s Lake</td>
<td align=left class="event">August 10, 2003</td>
</tr>
</table>
<br>
<h3>Sermons</h3>
<table>
<tr>
<td align=left style="background-color:#1D2C7F; color:white;" class="event">Title</td>
<td align=left style="background-color:#1D2C7F; color:white;" class="event">Date</td>
<td align=left style="background-color:#1D2C7F; color:white;" class="event">Book</td>
</tr>
<tr>
<td align=left class="event">The League of Extraordinary People</td>
<td align=left class="event">June 20, 2003</td>
<td align=left class="event">Romans 10</td>
</tr>
<tr>
<td align=left class="event">Seabiscuit Believers</td>
<td align=left class="event">July 27, 2003</td>
<td align=left class="event">Romans 12</td>
</tr>
</table>
</BODY>
</HTML>


This is the PHP Code: reservation.php then searching.php the only difference is the subect... can you help?!


<?PHP

$subject = "Reservation";
$headers = "From: Form Mailer";
$forward = 1;
$location = "thanks.html";
$addresses = array("webmaster@crosspoint.org","dvaughan@crosspoint.org","lhale@crosspoint.org");

$date = date ("l, F jS, Y");
$time = date ("h:i A");
$IP = $_SERVER['REMOTE_ADDR'];
$msg = "This form was submitted on $date at $time.\n\n";
$msg = $IP . $msg
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}

foreach ($addresses as $email) {
mail($email, $subject, $msg, $headers);
}
if ($forward == 1) {
header ("Location:$location");
}
else {
echo ("Thank you for submitting our form.");
}

?>

pyro
07-15-2003, 10:22 AM
Not sure where you got this code, but this is not going to work, unless they type you@domain.com:

if (document.front.Email.value!="" || document.front.Email.value!="you@domain.com")
{
if (document.front.Email.value.indexOf("@")==-1 || document.front.Email.value.indexOf(".")==-1 || document.front.Email.value.indexOf(" ")!=-1 || document.front.Email.value.length<6)
{alert("Your e-mail address is not valid, it must be in the following format: you@domain.com");
document.front.Email.focus();return false}
}

Jonathan
07-15-2003, 10:35 AM
oops :)

But my problem is I can't get it to return false if they input wrong data....

whats wrong with the script? I am saying if the e-mail doesn't = this then look at the syntax

Jonathan
07-15-2003, 10:42 AM
I found the checkdata() error