用户在点击时设置密码以锁定/解锁可填写表格

问题描述 投票:1回答:1

我希望创建一个表单,允许用户锁定他们各自的字段,但如果他们需要修改或更新任何信息,也可以再次解锁它们。然后将表单发送回完成的公司,但公司不应该能够编写/编辑用户输入字段。

我遇到的最接近的解决方案是一些脚本,要求用户在单击按钮时输入密码,然后此密码将锁定/解锁表单。但是,密码应该由用户在理想情况下首次单击按钮时设置。目前,已经在脚本中确定,这意味着公司必须与用户共享密码,从而破坏了锁定字段的整个目的。

这是如上所述的代码。任何让我更接近的东西将非常感激:

(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;

  }


})();
javascript acrobat
1个回答
1
投票

你不能在浏览器中这样做,你需要对表单和密码进行服务器验证,否则很容易从浏览器发送表单。

在这里看到代码的例子,validatePassword假设向服务器发出密码验证请求:

https://playcode.io/280470?tabs=console&style.css&output

© www.soinside.com 2019 - 2024. All rights reserved.