Sprout Posted July 11, 2010 Share Posted July 11, 2010 I just want to create a simple password check like most sites have, making sure you didn't have a typo when originally registering your password. So essentially what I have is <input type="text" name="pass1"> and <input type="text" name="pass2"> and I'd like to rig something up on the form processing page that checks to make sure pass1 is equal to pass2 otherwise it returns an error. Any help? Link to comment https://forums.phpfreaks.com/topic/207444-how-can-i-check-to-see-if-two-values-in-a-form-are-the-same/ Share on other sites More sharing options...
wildteen88 Posted July 11, 2010 Share Posted July 11, 2010 You'd use a basic if/else statement and the comparison operator if($_POST['pass1'] == $_POST['pass2'])) { // passwords match } else { // passwords do not match } Link to comment https://forums.phpfreaks.com/topic/207444-how-can-i-check-to-see-if-two-values-in-a-form-are-the-same/#findComment-1084568 Share on other sites More sharing options...
kenrbnsn Posted July 11, 2010 Share Posted July 11, 2010 You can do that in Javascript or PHP. In PHP <?php if ($_POST['pass1'] != $_POST['pass2']) { echo 'The two passwords are not the same, try again'; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/207444-how-can-i-check-to-see-if-two-values-in-a-form-are-the-same/#findComment-1084569 Share on other sites More sharing options...
Sprout Posted July 11, 2010 Author Share Posted July 11, 2010 Thanks for the quick responses, is there a way to stop the rest of the form from being submitted if those don't match? I don't want them to not match yet have the form still be submitted. Link to comment https://forums.phpfreaks.com/topic/207444-how-can-i-check-to-see-if-two-values-in-a-form-are-the-same/#findComment-1084575 Share on other sites More sharing options...
kenrbnsn Posted July 11, 2010 Share Posted July 11, 2010 That can only be done via Javascript. Ken Link to comment https://forums.phpfreaks.com/topic/207444-how-can-i-check-to-see-if-two-values-in-a-form-are-the-same/#findComment-1084578 Share on other sites More sharing options...
wildteen88 Posted July 11, 2010 Share Posted July 11, 2010 The form will have to be submitted in order for PHP to check the values. However using javascript you can control what happens with the form, such as disable the submit button if the passwords do not match and/or display an error message. You'll want to look into javascript form validation. Here is a quick tutorial http://www.w3schools.com/js/js_form_validation.asp You can however use a javascript framework such as jQuery for form validation http://yensdesign.com/2009/01/how-validate-forms-both-sides-using-php-jquery/ Link to comment https://forums.phpfreaks.com/topic/207444-how-can-i-check-to-see-if-two-values-in-a-form-are-the-same/#findComment-1084579 Share on other sites More sharing options...
Sprout Posted July 11, 2010 Author Share Posted July 11, 2010 Quote The form will have to be submitted in order for PHP to check the values. However using javascript you can control what happens with the form, such as disable the submit button if the passwords do not match and/or display an error message. You'll want to look into javascript form validation. Here is a quick tutorial http://www.w3schools.com/js/js_form_validation.asp You can however use a javascript framework such as jQuery for form validation http://yensdesign.com/2009/01/how-validate-forms-both-sides-using-php-jquery/ Exactly what I needed, thank you. Link to comment https://forums.phpfreaks.com/topic/207444-how-can-i-check-to-see-if-two-values-in-a-form-are-the-same/#findComment-1084585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.