-Karl- Posted April 16, 2010 Share Posted April 16, 2010 First of all, I'm not sure this is possible, but it's worth asking. I have my Javascript code function checkPasswordMatch(whatYouTyped) { var fieldset = whatYouTyped.parentNode; var txt1 = whatYouTyped.value; if (document.basicform.password.value == document.basicform.confirmpassword.value) { fieldset.className = "welldone"; } else { fieldset.className = "bad"; } } Which will display a green tick if both password fields match, this is for registration. However, is there a way I can Post the result of this to PHP, so that when they person actually submits the form it will either add it to the database if they are the same, or die if they are not. Without having to write a seperate PHP function. I know Javascript is client-side and PHP is server-side. I just don't want to write unnecessary code if there's no need. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/198775-javascript-and-php/ Share on other sites More sharing options...
andrewgauger Posted April 16, 2010 Share Posted April 16, 2010 Any validation on the client side will only mitigate server overhead, not eliminate it. Everything you do on the client side you need to re-validate with PHP. What if a user has Javascript disabled? Link to comment https://forums.phpfreaks.com/topic/198775-javascript-and-php/#findComment-1043217 Share on other sites More sharing options...
-Karl- Posted April 16, 2010 Author Share Posted April 16, 2010 Any validation on the client side will only mitigate server overhead, not eliminate it. Everything you do on the client side you need to re-validate with PHP. What if a user has Javascript disabled? Fair point, never thought about that Link to comment https://forums.phpfreaks.com/topic/198775-javascript-and-php/#findComment-1043219 Share on other sites More sharing options...
-Karl- Posted April 16, 2010 Author Share Posted April 16, 2010 Mm, this is strange. I have my PHP function: function verifyPassword() { $password1 = $_POST['password']; $master1 = $_POST['master']; if ($password1 == $master1) { return true; } else { return false; die('Passwords did not match'); } } and this is in my form if (isset($_POST['submit']) && verifyPassword == true) { Any ideas what I've done wrong as it still submits the data and creates the account whether both match or not. Link to comment https://forums.phpfreaks.com/topic/198775-javascript-and-php/#findComment-1043235 Share on other sites More sharing options...
-Karl- Posted April 16, 2010 Author Share Posted April 16, 2010 Nevermind if (isset($_POST['submit']) && verifyPassword == true) { just needed to be if (isset($_POST['submit']) && verifyPassword(true)) { Link to comment https://forums.phpfreaks.com/topic/198775-javascript-and-php/#findComment-1043271 Share on other sites More sharing options...
andrewgauger Posted April 17, 2010 Share Posted April 17, 2010 verifyPassword doesn't take arguments, you can do this: if (isset($_POST['submit']) && verifyPassword()) { and then you won't get debugging warnings. Link to comment https://forums.phpfreaks.com/topic/198775-javascript-and-php/#findComment-1043463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.