Skip to main content
maddyl31788266
Participant
April 12, 2016
Question

Password protect field (not secured)

  • April 12, 2016
  • 1 reply
  • 977 views

I would like to password protect a specific field.  I just want to prevent clients from entering data in the field, except for a specific few.  It does not have to be secure, if people end up adding data to the field it is not the end of the world, just annoying.  I have this so far, which seems to be working for the alert message however, when I enter the password, the field does not switch to allowing me to enter data into it.  Not sure if it is possible to have the field switch from read only to editable when the correct password is entered.  Here is what I have so far:

(function () {

    // Prefix for group field names. Change to match what you want to use.

    // Rename the fields you want to lock to match this prefix (e.g., "PRIV.NAME")

    var f_prefix = "MCC#";

    // Your chosen password goes here

    var pw = "1234";

    // Get a reference to the first field in the group

    var f = getField(f_prefix).getArray()[0];

    //Determine new readonly state, which is the opposite of the current state

    var readonly = !f.readonly;

    var readonly_desc = readonly ? "lock" : "unlock";

    //Prompt user for the password

     if (f.readonly) {

    var resp = app.response({

        cQuestion: "To unlock the fields, enter the password:",

        cTitle: "Enter password",

        bPassword: true,

        cLabel: "Password"

    });

   } else {

       var resp = pw;

   }

})();

Any help is much appreciated! Thanks!

This topic has been closed for replies.

1 reply

Inspiring
April 12, 2016

What is the name of the field you're trying to control? That code was intended to control a group of fields that use hierarchical field naming (e.g., group1.name, group1.address, group1.zip), as opposed to a single field. If you just want to control a single field, the code can be simpler, like this:

(function () {

    // Name of field

    var f = getField("field_name_to_control");

    // Your chosen password goes here

    var pw = "1234";

    //Determine new readonly state, which is the opposite of the current state

    var readonly = !f.readonly;

    var readonly_desc = readonly ? "lock" : "unlock";

    //Prompt user for the password

     if (f.readonly) {

    var resp = app.response({

        cQuestion: "To unlock the field, enter the password:",

        cTitle: "Enter password",

        bPassword: true,

        cLabel: "Password"

    });

   } else {

       var resp = pw;

   }

})();

maddyl31788266
Participant
April 12, 2016

The name of my field is "MCC#", I am now using your simplified formula but still having trouble with the field becoming fillable.  I am still getting the error message with password, but when I enter the correct password it does not change the field to fillable unfortunately. Thank you so much for the simplified formula! I am new to java/adobe forms, so I am sure my code is redundant and repetitive, this helps a lot!

Inspiring
April 12, 2016

I just realized that some code is missing from what you originally, which is from on old post here. I'll post an update in a bit...