We have found PDF form names can be a little confusing, so it seemed like a good topic for a blog article.
“The Form fields within a PDF file all have there own name right?”
Some have a name and some don’t, some are just another field with the same name as another field.
“So why do they have the same name?”
you ask. Well that is generally because they are part of a group by that name that all represent one object. Examples of this might be a set of radio buttons :-
yes / no / cancel
You want only one of these to be selectable at one time, so that the user cannot answer yes and no to the same question.
“These 3 buttons are then grouped under one name, but what name and how do we know what it is?”
Well each will have a parent form, and if this is setup correctly they will all have the same parent so the name will be in the parent form, which can also define values that are the same for all 3 fields.
Unfortunately that is not the end as the parent can be a child of another field, which can be a placeholder field for a page for example.
So now we could have a page “page1” with 4 forms on – tom, john, harry, mark,
john has 3 children – 1,2,3,
harry also has 3 children (but they dont have a name, but some of there values are different, so we do need to track there differences).
So the field “2” has the full name page1.john.2, which is a unique field.
Where as the full name page1.harry, points to 3 fields.
So how do we get the the unique field within “harry” that we want?
All the fields have there own PDF reference, so can be found specifically by that.
To work out the fully qualified name for any given field.
1. you read that fields name
2. you read its parents name
3. if the field Does NOT have a name then the parent name is stored.
4. you loop getting the parent of the parents name, and store that before the currently stored name with a “.” in the middle to show a descendent (if any names do not exist they are ignored)
One last thing… You only go back to the top acroform element in the PDF structure, you do NOT use the page and file object names.