Lamez Posted October 2, 2007 Share Posted October 2, 2007 I was wanting to know how can I make more than one form action? In my form I need a captcha action, a validate form action(it makes sure the forms are filed in), and a verify password action Quote Link to comment Share on other sites More sharing options...
jbingman Posted October 2, 2007 Share Posted October 2, 2007 Just put all make a function for each seperate action in side an action.html file. One for the verify fields, verify password, and captcha. Then post the action as action.html. Quote Link to comment Share on other sites More sharing options...
Lamez Posted October 2, 2007 Author Share Posted October 2, 2007 Alright, but I am not sure on how to mix 2 javascripts and one php script. Can you help me do that? Quote Link to comment Share on other sites More sharing options...
jbingman Posted October 2, 2007 Share Posted October 2, 2007 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> Quote Link to comment Share on other sites More sharing options...
Lamez Posted October 2, 2007 Author Share Posted October 2, 2007 I know, but how do I mix my 2 JavaScripts? Quote Link to comment Share on other sites More sharing options...
Lamez Posted October 2, 2007 Author Share Posted October 2, 2007 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? Quote Link to comment Share on other sites More sharing options...
jbingman Posted October 2, 2007 Share Posted October 2, 2007 try: <form action="validate.js"> //form input <?php if (chk_crypt($_POST['code'])) echo "<a><font color='#009700'>Correct</font></a>" ; else echo "<a><font color='#FF0000'>Incorrect</font></a>" ; ?> </form> Quote Link to comment Share on other sites More sharing options...
Lamez Posted October 3, 2007 Author Share Posted October 3, 2007 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. Quote Link to comment Share on other sites More sharing options...
d22552000 Posted October 8, 2007 Share Posted October 8, 2007 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; } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.