...

View Full Version : simple form control not working



questor
05-14-2004, 08:12 AM
Heya, this is my first post here.

Now that I understand a bit of javascript I'm going through my apps and removing php form control and adding javascript. The basic 'did you complete all required fields' stuff. Obviously javascript is better because it will do it before you leave the page.

Well, on one page it's not working; it just lets the user glide on to the next page without input and without the err msg. I don't see how it's significantly different than any other page.

Here's the code.

<?php
include("functions.php");
secure();
$dbconnect=@mysql_connect("localhost","###","###");
if (!$dbconnect) {
die ("Error: No connection to the server established. ".mysql_error());
}
mysql_select_db("pmap");
?>

<script>
self.resizeTo(460,460);
</script>

<HTML>
<head>
<title>THE SEXTANT</title>
<link rel="stylesheet" type="text/css" href="main.css">

<script>
function validate()
{
old=mainform.old_password.value;
new=mainform.new_password.value;

fail=0;

if (old=='')
{
fail=1;
}

if (new=='')
{
fail=1;
}

if (fail==1)
{
alert('Please complete all fields.');
event.returnValue=false;
}
}
</script>

</head>
<body>
<center><img src="./images/step_one.jpg"></center>

<center><table align=center border="0"></center>
<tr><td class="noBorder" valign="top">
<img src="./images/sextant_background.jpg">

<div id="menu">
<form name="mainform" action="passchangeaction.php" method="post" onsubmit="validate();">
<center><table></center>
<tr><td>
Old Password:</td><td><input type="password" name="old_password" size="10"></input></td></tr><td>
New Password:</td><td><input type="password" name="new_password" size="10"></input></td></tr>
<tr><td>&nbsp</td></tr>
<tr><td align=center colspan=2><input type="Submit" value="Update Password"></td></tr>
</table>
</form>
</table>
</div>

<div id="nav">
<center><A HREF="index.php"><img src="./images/back_arrow.gif" alt="Back" border=0></A> <A

HREF="index.php"><img src="./images/up_arrow.gif" alt="Home" border=0></A></center>
</div>

</body>
</html>

questor
05-14-2004, 08:35 AM
Okay, so I just changed the var names 'old' and 'new' to 'oldpassword' and 'newpassword' and it worked.

Wt?

So what, old and new are reserved terms?

glenngv
05-14-2004, 08:39 AM
function validate(f)
{
if (f.old_password.value==''){
alert("Old password is empty.");
f.old_password.focus();
return false;
}
if (f.new_password.value==''){
alert("New password is empty.");
f.new_password.focus();
return false;
}
return true;
}
...
<form name="mainform" action="passchangeaction.php" method="post" onsubmit="return validate(this);">
...
<input type="Submit" value="Update Password" />
</form>

But definitely, you should ALWAYS validate on the server-side. Don't rely on javascript as this can be disabled.

questor
05-14-2004, 08:46 AM
damnit. you're right. >:( I just went through and changed all this stuff to javascript.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum