eDocEngine VCL Professional Help » Symbol Reference » Namespaces of Helper Classes » gtExPDFEng Namespace » TgtPDFFormPushButton Class

Gnostice eDocEngine VCL Developer Guide
TgtPDFFormPushButton Class

This class represents a push button form field.

Pascal
public TgtPDFFormPushButton = class(TgtPDFFormField);
C++
public: class TgtPDFFormPushButton : public TgtPDFFormField;
Description

A push button form field can be used to initiate an action related to the form. Typically, it is used to submit or reset a form. It can also be used to make the viewer application execute a JavaScript script.

gtExPDFEng

procedure TForm1.Demo_TgtPDFFormPushButton;
var
  gtPDFFormTextField1: TgtPDFFormTextField;
  gtPDFFormPushButton1, gtPDFFormPushButton2: TgtPDFFormPushButton;
  gtPDFEngine1: TgtPDFEngine;
begin
  gtPDFEngine1 := TgtPDFEngine.Create(Nil);

  // Create a text field
  gtPDFFormTextField1 := TgtPDFFormTextField.Create;
  gtPDFFormTextField1.Rect := gtRect(1, 1, 3, 1.5);
  gtPDFFormTextField1.FieldName := 'tfName';

  // Create a pusb button for validation
  gtPDFFormPushButton1 := TgtPDFFormPushButton.Create;
  gtPDFFormPushButton1.Rect := gtRect(3.5, 1, 4.5, 1.5);
  gtPDFFormPushButton1.FieldName := 'pbValidate';
  gtPDFFormPushButton1.NormalCaption := 'Validate';
  gtPDFFormPushButton1.RolloverCaption := 'Validate';
  gtPDFFormPushButton1.DownCaption := 'Validate';
  gtPDFFormPushButton1.Action := pbaJavaScript;
  gtPDFFormPushButton1.JavaScript :=
    ' var tf1 = this.getField("tfName");             ' +
    ' var btn1 = this.getField("pbValidate");        ' +
    ' var btn2 = this.getField("pbSubmit");          ' +
    ' if (tf1.valueAsString.length > 3) {            ' +
    '   tf1.value = tf1.valueAsString.toUpperCase(); ' +
    '   btn2.buttonSetCaption("Submit");             ' +
    '   btn1.display = display.hidden;               ' +
    '   btn1.setFocus();                             ' +
    ' } else {                                       ' +
    '   app.alert("Please enter a valid name.");     ' +
    '   tf1.setFocus();                              ' +
    ' }';
  // If the validation push button is pressed, viewer
  // application executes the above JavaScript script.
  // The script checks if there is valid data in the
  // text field. If there is invalid data, it displays
  // an error message. Otherwise, it shifts focus to
  // the submit button.

  // Create another push button form field for form submission
  gtPDFFormPushButton2 := TgtPDFFormPushButton.Create;
  gtPDFFormPushButton2.Rect := gtRect(1, 2, 3, 2.5);
  gtPDFFormPushButton2.FieldName := 'pbSubmit';
  gtPDFFormPushButton2.NormalCaption := 'Click "Validate" First';
  gtPDFFormPushButton2.RolloverCaption := 'Submit';
  gtPDFFormPushButton2.DownCaption := 'Submit';
  gtPDFFormPushButton2.Action := pbaSubmit;
  gtPDFFormPushButton2.SubmitURL :=
    'http://www.gnostice.com/newsletters/demos/200804/forms_test.asp';

  with gtPDFEngine1 do
  begin
    Preferences.ShowSetupDialog := False;
    Preferences.OpenAfterCreate := True;
    FileName := 'pushbutton_formfield.pdf';

    BeginDoc;

    TextOut(1,0.8,'Enter your name in this box and click "Validate"');
    TextOut(1,1.8,'Click this button after validating your name');

    // Add form fields to current page
    AddFormItem(gtPDFFormTextField1);
    AddFormItem(gtPDFFormPushButton1);
    AddFormItem(gtPDFFormPushButton2);

    EndDoc;
  end;
end;

 

 

When a user presses the "Validate" push button, the viewer application executes the Javascript action of the pushbutton. The JavaScript script of action checks if the "name" box contains a valid name. If the user had entered a valid name, the JavaScript script upper cases the name value, disables the "Validate" push button and sets the caption of the "submit" push button. 

 

When the user clicks the "Submit" button, the viewer application submits the form and the form is processed by the Web resource at the "submit URL" of the "submit" button. 

 

Properties
TgtPDFFormPushButton Class
 
Name 
Description 
 
Specifies action that viewer applications need to perform when the button is selected by the user. 
 
Specifies an "alternate" name for the form field. 
 
Specifies background color of the form field. 
 
Specifies border color of the form field. 
 
Specifies caption of the button when it is held down by the user. 
 
Specifies name of the form field. 
 
Font 
Specifies font used to display the contents of the form field. 
 
Specifies format in which the form contents need to be submitted by viewer applications. 
 
Specifies JavaScript script that needs to be executed when the button is selected by the user. 
 
Specfies caption of the button when the user is not interacting with it. 
 
Specifies settings applicable to the form field. 
 
Rect 
Specifies location on the page where the form field is displayed. 
 
Specifies caption of the push button when the user moves the mouse pointer over the button. 
 
Specifies URI to which the form contents need to be submitted. 
 
Specifies whether the form field is displayed on the page. 
Methods
TgtPDFFormPushButton Class
 
Name 
Description