Jump to content

More than One Form Action


Lamez

Recommended Posts

Put the javascript in an external .js file for the form validation. Then make an action.php script with the form process. Or you can just put the javascript in the head section of the same file. I personally think its cleaner to use an external. so...

 

<head>
<script language="javascript">
//your javascript validation code here
</script>
</head>
<body>
<form action="action.php">
//form inputs here
</form>
</body>

Link to comment
Share on other sites

Here My Validation Script (JS)

<script type="text/javascript">
function setFocus(aField) {
document.forms[0][aField].focus();
}

function isAnEmailAddress(aTextField) {

if (document.forms[0][aTextField].value.length<5) {
return false;
}
else if (document.forms[0][aTextField].value.indexOf("@") < 1) {
return false;
}
else if (document.forms[0][aTextField].value.length -
document.forms[0][aTextField].value.indexOf("@") < 4) {
return false;
}
else { return true; }
}

function isEmpty(aTextField) {
if ((document.forms[0][aTextField].value.length==0) ||
(document.forms[0][aTextField].value==null)) {
return true;
}
else { return false; }
}
function validate() {

if (isEmpty("username")) {
alert("Please fill your username.");
setFocus("username");
return false;
}
if (isEmpty("password")) {
alert("Please fill in your password.");
setFocus("password");
return false;
}
if (!isAnEmailAddress("email")) {
alert("The entered email address is invalid.");
setFocus("email");
return false;
}
return true;

}
</script>

 

Here is My Password Validation (JS)

<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Russ Swift (rswift220@yahoo.com) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.myForm.password.value;
var pw2 = document.myForm.password2.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (document.myForm.password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.myForm.password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else {
alert('Nice job.');
return true;
      }
   }
}
//  End -->
</script>

 

Here is My Captcha (PHP)

<?php   
if (chk_crypt($_POST['code'])) 
echo "<a><font color='#009700'>Correct</font></a>" ;
else echo "<a><font color='#FF0000'>Incorrect</font></a>" ;
?>

 

Any Ideas?

Link to comment
Share on other sites

Wow never thought to do it that way, but I seriously need help mixing the JavaScript's, and by that I mean take one script and add it to the other one to make it work, but I have no experience with it at all, please help me with this.

Link to comment
Share on other sites

here is yoru mixed JS:

 

function setFocus(aField) {
document.forms[0][aField].focus();
}

function isAnEmailAddress(aTextField) {

if (document.forms[0][aTextField].value.length<5) {
return false;
}
else if (document.forms[0][aTextField].value.indexOf("@") < 1) {
return false;
}
else if (document.forms[0][aTextField].value.length -
document.forms[0][aTextField].value.indexOf("@") < 4) {
return false;
}
else { return true; }
}

function isEmpty(aTextField) {
if ((document.forms[0][aTextField].value.length==0) ||
(document.forms[0][aTextField].value==null)) {
return true;
}
else { return false; }
}
function validate() {

if (isEmpty("username")) {
alert("Please fill your username.");
setFocus("username");
return false;
}
if (isEmpty("password")) {
alert("Please fill in your password.");
setFocus("password");
return false;
}
if (!isAnEmailAddress("email")) {
alert("The entered email address is invalid.");
setFocus("email");
return false;
}
return true;
}

// THIS IS THE SPACE BETWEEN THE SCRIPTS //

function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.myForm.password.value;
var pw2 = document.myForm.password2.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (document.myForm.password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.myForm.password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else {
alert('Nice job.');
return true;
      }
   }
}

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.