Reply
Form Validation
Old 04-04-2005, 09:38 PM Form Validation
Experienced Talker

Posts: 34
I don't know if Javascript is the best option for form validation, so please advise. I have one .html page, the HTML of which is located below. Basically, I need to be able to...

(1) Run a quick javascript task that will make sure that all forms have been filled in, make sure that the "Email Address" form and the "Verify Email Address" form match, as well as make sure that the "Password" form and the "Verify Password" form match.

(2) Run a php script that will write the data to a flat file.

I have the php script, and I have two separate javascript codes lined up to do the job. Only, I can't impliment them all. (This, I'm sure, has something to do with the fact that you can't have more than one onSubmit action.)

HTML Code:
<html><head></head><body>

<form onSubmit="return checkrequired(this)">

  <div align="left">
    <table width="600" border="0" align="left">
      <tr>
        <td width="226">First Name:          </td>
        <td width="364"><input type="text" name="requiredFirst Name"></td>
      </tr>
      <tr>
        <td>Last Name:          </td>
        <td><input type="text" name="requiredlast name"></td>
      </tr>
      <tr>
        <td>Email (This will be your username):</td>
        <td><input type="text" name="requiredemail"></td>
      </tr>
      <tr>
        <td>Verify Email </td>
        <td><input type="text" name="requiredVerify Email"></td>
      </tr>
      <tr>
        <td>Password:</td>
        <td><input type="password" name="requiredpassword"></td>
      </tr>
      <tr>
        <td>Repeat your Password:</td>
        <td><input name="requiredrepeatpassword" type="password" id="requiredrepeatpassword">          </td>
      </tr>
    </table>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>
      <input name="submit" type=submit value="Submit">
</p>
  </div>
</form>


</body></html>
By the way, I'm new to these forums, and I thank you for being around! I have been messing around with HTML for around six years. My largest dilemma has always been that I do not have Javascript abilities... Now that I'm finally stepping into the future by dabbling with PHP, I'm having a blast with interactivity! If I could only get it to work. Java has always frustrated me, as it never seems logical, and I've never successfully designed my own script.

Thank you,

Andrew
mtairhead is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 04-04-2005, 10:19 PM
Phaedrus's Avatar
Ultra Talker

Posts: 271
Location: CA
I'm not sure what your question is, but you can run your JavaScript code in the "onSubmit" attribute (personally I like the "onClick" event of the submit button, "onSubmit" doesn't work in some browsers) and you can run your PHP code in the page that the form "action" attribute is set to.
__________________
Free Teacher Websites
Phaedrus is offline
Reply With Quote
View Public Profile
 
Old 04-04-2005, 11:20 PM
Experienced Talker

Posts: 34
My mistake... Actually, I think I've corrected the issue. I've posted the code below. I broke out a JavaScript book that I thought I had lost a long time ago. Please post any suggestions you might have. Phaedrus suggested that I use the "onClick" method, instead of the "onsubmit" and I've done so in the code.

HTML Code:
<html>
<head>


</head><body>
<script language="javascript">
function validate() {
	if (document.form1.fname.value.length < 1) {
		alert("Please enter your full first name.");
		return false;
	}
	if (document.form1.lname.value.length < 1) {
		alert("Please enter your full last name.");
		return false;
	}
	if (document.form1.email.value.length < 6) {
		alert("Please enter your full e-mail address. You will use this as your username, so it must be correct.");
		return false;
	}
	if (document.form1.password.value.length < 1) {
		alert("Please enter a password.");
		return false;
	}
	if (document.form1.password.value.length < 6) {
		alert("Your password must be at least six characters.");
		return false;
	}
	if (document.form1.password.value != document.form1.vpassword.value) {
		alert("Your passwords do not match. Please check them and try again.");
		return false;
	}
	if (document.form1.email.value != document.form1.vemail.value) {
		alert("Your email addresses do not match each other. Please check the VERIFY EMAIL section.");
		return false;
	}
	return true;
}
</script>
<form name="form1" action="../php/register.php">

  <div align="left">
    <table width="600" border="0" align="left">
      <tr>
        <td width="226">First Name:          </td>
        <td width="364"><input name="fname" type="text" id="fname"></td>
      </tr>
      <tr>
        <td>Last Name:          </td>
        <td><input name="lname" type="text" id="lname"></td>
      </tr>
      <tr>
        <td>Email (This will be your username):</td>
        <td><input name="email" type="text" id="email"></td>
      </tr>
      <tr>
        <td>Verify Email </td>
        <td><input name="vemail" type="text" id="vemail"></td>
      </tr>
      <tr>
        <td>Password:</td>
        <td><input name="password" type="password" id="password"></td>
      </tr>
      <tr>
        <td>Repeat your Password:</td>
        <td><input name="vpassword" type="password" id="vpassword">          </td>
      </tr>
    </table>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>
      <input name="submit" type=submit value="Submit" onSubmit="return validate();">
</p>
  </div>
</form>

</body></html>
Now, I don't suppose that I could use JavaScript to lookup a record on the flat file that I just created, and identify whether or not the username (In this case, the email address of the user) is already in the database. This would allow me to prevent the same person from accidentally signing up twice. I think that I have to use php, but if I can use JavaScript, I'm open to it. Anyone know any good resources on doing either?

Thanks,

Andrew

//Edit: Removed some javascript from the above code, which is no longer in use.

Last edited by mtairhead : 04-05-2005 at 07:12 AM.
mtairhead is offline
Reply With Quote
View Public Profile
 
Old 04-05-2005, 12:52 PM
Kaiman's Avatar
Extreme Talker

Posts: 237
mtairhead,

Your going to want to use something like PHP or ASP (depending on whether your database is MySQL MS SQL Access or whatnot) to check the database for a username or password because Javascript is limited in this regard. While you are at it you can also validate your form with PHP/ASP as well. You might post this question to the PHP portion of this site and see if the folks over there can help you out. It is more complicated but also better to learn in the longrun.

Good Luck!

Kaiman

Storm King Website and Graphic Design
Kaiman is offline
Reply With Quote
View Public Profile
 
Old 04-05-2005, 07:53 PM
Experienced Talker

Posts: 34
Thank you.

I think I will post a similar cry for help within the PHP forums. Bascially, I need a PHP login script... Well, what I would really like is a great tutorial on how to use my flatfile database.... Query records (If I could do that, it would cover login, I suppose), edit records, etc.

I've made the request on the PHP forum, and will post the link to it in a few seconds...
mtairhead is offline
Reply With Quote
View Public Profile
 
Old 04-05-2005, 08:17 PM
Experienced Talker

Posts: 34
http://www.webmaster-talk.com/showth...365#post138365
mtairhead is offline
Reply With Quote
View Public Profile
 
Old 04-05-2005, 08:24 PM
brokensoul2271's Avatar
- - - - - - - - -

Posts: 750
Location: Lancashire, UK
May I just say that its probably a better idea to validate forms using JavaScript as this is client side and will do the job faster. Just leave all the complicated stuff too the server side technologies (PHP and what-not)
__________________
Yes, indeed...
WebDevWorld.net | StrangeDarkness.com | MyNEWBlog
brokensoul2271 is offline
Reply With Quote
View Public Profile Visit brokensoul2271's homepage!
 
Old 04-05-2005, 10:10 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Just bear in mind that if someone doesn't have Javascript enabled, they can't use your form, whereas serverside validation works no matter what.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Scribble Pad MOD for phpBB (aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 04-05-2005, 10:12 PM
brokensoul2271's Avatar
- - - - - - - - -

Posts: 750
Location: Lancashire, UK
Ah true so true...
__________________
Yes, indeed...
WebDevWorld.net | StrangeDarkness.com | MyNEWBlog
brokensoul2271 is offline
Reply With Quote
View Public Profile Visit brokensoul2271's homepage!
 
Reply     « Reply to Form Validation
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.18031 seconds with 12 queries