Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Password protect field (not secured)

New Here ,
Apr 12, 2016 Apr 12, 2016

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!

TOPICS
Acrobat SDK and JavaScript , Windows
921
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 12, 2016 Apr 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;

   }

})();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 12, 2016 Apr 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 12, 2016 Apr 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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 12, 2016 Apr 12, 2016

Here's the corrected code:

(function () {

    // Your chosen password goes here

    var pw = "1234";

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

    var f = getField("WCC#");

    //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

    var resp = app.response({

        cQuestion: "To" + readonly_desc + "the field, enter the password:",

        cTitle: "Enter password",

        bPassword: true,

        cLabel: "Password"

    });

    switch (resp) {

    case pw:

        f.readonly = readonly;

        app.alert("The field is now " + readonly_desc + "ed.", 3);

        break;

    case null:  // User pressed Cancel button

        break;

    default:  // Incorrect password

        app.alert("Incorrect password.", 1);

        break;

    }

})();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 13, 2016 Apr 13, 2016
LATEST

Ah, I see.  I have tried adding that section but for some reason I cannot get it to except it.  It is saying I have a syntax error (missing a } after property list 20; at line 21.  The case pw, right after the switch (resp) line.  I have tried adding it in a bunch or different ways but I can't seem to get it to work correctly. I do not know enough about java to see my mistake.  Thank you for your help though!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines