Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

Get data from radio button form fields

Question

How do I retrieve data from radio button form fields in my PDF? I'm a bit confused as to how to do this using Quick PDF Library. It's fairly easy to retrieve data for text form fields, but radio form fields looks difficult. Do you have any sample code?

Answer

Radio buttons that use the same title are considered to be part of a radio button group. Each radio button that belongs to the group is a child or sub-radio button.

This means that you can use the GetFormFieldTitle and GetFormFieldValue functions to find out the title and selected value of a radio button group.

So for example, if you have a radio button group which has the title Nationality and this group has sub-radio buttons with the export values of Australian, French, German, American and Chinese, but the Australian sub-radio button is the radio button which is selected in the PDF form, then the GetFormFieldValue function will return a value of Australian for the Nationality radio button group.

The code for this would look something like the below:

// Loop through all of the form fields in the PDF
for i := 1 to QP.FormFieldCount do
begin
    // Only process radio buttons
    if QP.GetFormFieldType(i) = 4 then
    begin
        // Get radio button group title and selected value
        WriteLn(IntToStr(i) + '. Group');
        WriteLn;
        WriteLn('Radio Button Group: ' + QP.GetFormFieldTitle(i));
        WriteLn('Selected Radio Button Value: ' + QP.GetFormFieldValue(i));
        Writeln;
    end;
    ReadLn;
end;

If you wanted to get the radio button group title, selected value and a full list of all the sub-radio buttons that belong to the radio button group, then you could do it like this:

// Loop through all of the form fields in the PDF
for i := 1 to QP.FormFieldCount do
begin
    // Only process radio buttons
    if QP.GetFormFieldType(i) = 4 then
    begin
        // Get radio button group title and selected value
        WriteLn(IntToStr(i) + '. Group');
        WriteLn;
        WriteLn('Radio Button Group: ' + QP.GetFormFieldTitle(i));
        WriteLn('Selected Radio Button Value: ' + QP.GetFormFieldValue(i));
        Writeln;
        end;
        ReadLn;
        end;

        // Get all of the sub-radio buttons from the radio button group
        WriteLn('Child Radio Buttons In This Group:');
        WriteLn;
        if QP.GetFormFieldKidCount(i) <> 0 then
        for j := 2 to QP.GetFormFieldSubCount(i) do
        begin
        s := QP.GetFormFieldSubTempIndex(i, j);
        WriteLn(QP.GetFormFieldSubName(i, j));
        end;
        Writeln;
    end;
    ReadLn;
end;

These examples are written in Delphi and use a console application, however, they should be fairly easy to understand for any programmer and can easily be adjusted to work with a GUI application. If you experience any problems, please leave a comment.


© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum