MeOnTheWeb Posted May 26, 2018 Share Posted May 26, 2018 Hi, So I have a form with various fields. One is a CHECKBOX - if the user wants the app to generate a password, they check this. Then I have a password field where the input type is password. On the checkbox, I have ONCLICK to execute a piece of javascript called generatepassword. Inside that code, I call a PHP function to create the password. function generatePassword() { // Get the checkbox var checkBox = document.getElementById("generateuserpassword"); // Get the output text var passvalue = document.getElementById("setuserpassword"); // If the checkbox is checked, display the output text if (checkBox.checked == true) { // Generated password. User may or may not have accepted this passvalue.value = '<?php echo genPassword(15); ?>'; passvalue.disabled = true; } } When I view the source I do see this: // Generated password. User may or may not have accepted this passvalue.value = 'S<?#{FrZ[COB7AG'; passvalue.disabled = true; and I use some code to get the post variables $userpassword = htmlspecialchars($_POST['setuserpassword']); When I print out $userpassword it is always BLANK. I can't figure out what I'm doing wrong. I have confirmed the input type, id and name. Quote Link to comment https://forums.phpfreaks.com/topic/307307-setting-html-form-field-not-working/ Share on other sites More sharing options...
kicken Posted May 27, 2018 Share Posted May 27, 2018 (edited) Quote passvalue.disabled = true; If you disable a form field, then it will not be sent when the form is submitted. Use the readonly attribute to prevent a user modifying it. If you want the disabled look, simulate it with CSS. Edited May 27, 2018 by kicken 1 Quote Link to comment https://forums.phpfreaks.com/topic/307307-setting-html-form-field-not-working/#findComment-1558598 Share on other sites More sharing options...
MeOnTheWeb Posted May 27, 2018 Author Share Posted May 27, 2018 Jeez... of course, that was the issue. I was beating my head against the wall to figure this out. So simple to fix. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/307307-setting-html-form-field-not-working/#findComment-1558599 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.