Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/307307-setting-html-form-field-not-working/
Share on other sites

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 by kicken
  • Thanks 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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