Jump to content

Javascript and PHP


-Karl-

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.