PDF 中的多选表单字段
使用 PDF,是否可以创建具有多个字段(其中多个字段可以选择)的单个表单元素?例如,在 HTML 中,可以创建一组与相同字段名称关联的复选框:
<div>Select one for Member of the School Board</div>
<input type="checkbox" name="field(school)" value="vote1">
<span class="label">Libby T. Garvey</span><br/>
<input type="checkbox" name="field(school)" value="vote2">
<span class="label">Emma N. Violand-Sanchez</span><br/>
在本例中,字段名称为“field(school)”,提交表单时可将“field(school)”供给 0、1 或 2 次。
PDF 中是否有等效的构造,其中单个字段可以有多个值。到目前为止,在我的调查中,似乎如果为字段指定了相同的名称,则只能选择一个字段。如果可以在 PDF 中实现这一点,那么这个结构叫什么以及如何实现?
编辑:为了澄清,我知道 PDF 可以包含具有不同字段名称的多个表单字段,并且可以独立选择这些字段,但分组是隐式的,而不是像 HTML 表单那样显式。我想使用一种使选项分组明确的构造,并且最好允许限制(例如,至少需要一个,允许不超过 2 个,等等)。
编辑:如果有人能找到一个权威的意见来证明这是不可能的,那也是一个理想的答案。
Using PDF, is it possible to create a single form element with multiple fields of which several can be selected? For example, in HTML, one can create a set of checkboxes associated with the same field name:
<div>Select one for Member of the School Board</div>
<input type="checkbox" name="field(school)" value="vote1">
<span class="label">Libby T. Garvey</span><br/>
<input type="checkbox" name="field(school)" value="vote2">
<span class="label">Emma N. Violand-Sanchez</span><br/>
In this case, the field name is "field(school)", and when the form is submitted, "field(school)" can be supplied 0, 1, or 2 times.
Is there an equivalent construct in PDF where a single field can have multiple values. So far in my investigation, it appears that if fields are assigned the same name, it is only possible to select one field. If it is possible to implement this in PDF, what is this construct called and how can it be implemented?
Edit: To clarify, I am aware that a PDF can contain multiple form fields with different field names, and those can be selected independently, but then the grouping is implicit and not explicit as with the HTML form. I would like to use a construct that makes the grouping of options explicit, and preferably allows for restrictions (e.g. at least one required, no more than 2 allowed, etc).
Edit: If someone can find an authoritative opinion that this is not possible, that would also be a desirable answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是可能的。在 Adobe PDF 中,您有复选框概念和单选按钮概念。虽然每个复选框和单选按钮都可以有自己的名称,但它们也可以通过 GroupName.subobj 通过子层进行分组。
Adobe对此的描述如下:
当通过层次结构设置字段时,您可以在本例中获取 myGroup 的值,并返回该组的选定值。同样,对于单选按钮,您需要确保组中的所有字段都具有相同的名称。
Yes it is possible. In Adobe PDFs you have the checkbox concept and the radio button concept. While each checkbox and radio button can have its own name, however, they can also be grouped through a subtier via the GroupName.subobj.
Adobe describes it as follows:
When the fields are set via a hierarchy you can then get the value of myGroup in this case, and return the selected value of the group. Similarly in the case of RadioButtons you would make sure that all fields in a group have the same name.
asnyder 的回应让我得出这样的结论:没有一种自动方法可以处理单个字段中的多个值(就像 HTML 一样)。 asnyder 的示例来自使用 JavaScript 开发 Acrobat 应用程序,可从 Acrobat Javascript 开发人员中心。本文档提供了一些如何操作复选框、组合框和单选按钮的示例。所有示例都阐明了该问题,并最终使我得出结论:任何使用 PDF 表单的系统都将隐式定义任何多选组。
使用 groupName.fieldName 的构造对于将小部件作为一个组进行操作(在 Acrobat Javascript 中)似乎很有用,但是无法枚举组的字段(无需枚举所有字段并过滤 groupName),并且如果不以编程方式检查值,则无法确定该组。
换句话说,多选值在任何实质上都不是 Acrobat 或 PDF 的固有特征,尽管可以通过编程实现这种形式。
asnyder's response led me to the conclusion that there is no automatic way to handle multiple values within a single field (as one can with HTML). asnyder's examples come from Developing Acrobat Applications Using JavaScript, available from the Acrobat Javascript Developer Center. This document provides some examples of how to manipulate checkboxes, combo boxes, and radio buttons. All of the examples shed some light on the problem and ultimately led me to the conclusion that any system that is using PDF forms will have any multi-selectable groups implicitly defined.
Using the construct of groupName.fieldName appears to be useful to manipulate the widgets as a group (in Acrobat Javascript), but the fields of a group cannot be enumerated (without enumerating all fields and filtering for the groupName), and the collective value of that group cannot be determined without programatically inspecting the values.
In other words, a multi-selectable value is not an intrinsic feature of Acrobat nor of PDF in any substantial way, though it is possible to implement such a form through programming.