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

User set password to lock/unlock fields via javascript button

New Here ,
Apr 01, 2019 Apr 01, 2019

Copy link to clipboard

Copied

I am looking to create a form that allows a user to lock their respective fields, but also unlock them again, should they need to amend or update any of the information. The form is to then be sent back to the company, where it is completed, but the company should not be able to write/edit the user-input fields.

The closest solution I have come across is some script that requires the user to enter a password on clicking a button, and this password will then lock/unlock the form. The password however, should be set by the user, on first click of the button ideally. Currently, it is already determined within the script, meaning the company would have to share the password with the user, defeating the whole purpose of locking the fields.

This is the code as described above. Anything that gets me closer would be much appreciated:

(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 = "PRIV";

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

    var resp=app.response({

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

        cTitle: "Enter password",

        bPassword: true,

        cLabel: "Password"

    });

    switch (resp) {

    case pw:

        getField(f_prefix).readonly = readonly;

        app.alert("The fields are now " + readonly_desc + "ed.", 3);

        break;

    case null:  // User pressed Cancel button

        break;

    default:  // Incorrect password

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

        break;

    }

})();

TOPICS
Acrobat SDK and JavaScript

Views

725

Translate

Translate

Report

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
Community Expert ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

First, that code is useless to us. Only post formatted code that we can read.

Next, this type of thing can be complicated and unless you have some kind of server control of over the process, it is not secure. The best you can do is fake security, like the code you posted.

Is this what you want?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Thanks, and apologies Thom - everytime I paste the script in the code formatter whilst composing the message, it rendered without proper styling.

I don't have server control over this process. I think my best alternative for this situation would be to create a function that requires the user to save a copy first, before the option to lock the fields is enabled. That way, once sent to the company, the fields can't be edited, but the user has a copy prior to locking the fields, should they need to amend/edit of the fields again.

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

LATEST

Another option is for the user to digitally sign/certify the PDF.  The signature field provides an option for locking certain fields. This is not a hard security lock, but it's better than just setting the fields to ReadOnly. But the power of signing is that it ensures the signature will be invalid if any of the fields are changed. So while you can't stop a motivated user from changing the "locked" fields, you can ensure any changes will be detected.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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