• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Conditional action on buttons

Community Beginner ,
Oct 07, 2018 Oct 07, 2018

Copy link to clipboard

Copied

I have a button where Ive set the action to submit the form followed by an action to clear the form fields. Is there a way to make the clear form fields conditional upon the 'submit' action actually happening (when required fields aren't filled the submit button fails but then clear the form as well!)

TOPICS
Acrobat SDK and JavaScript

Views

341

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

Use Javascript code for this. Check the required fields. When all required fields are filled submit the form and clear the form.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

As Bernd says, you'll need to write a script for this type of task. However, it's not as simple as you might hope.

Here is an of articles that will point you in the right direction:

https://acrobatusers.com/tutorials/submitting-data

https://acrobatusers.com/tutorials/conditional-execution

If you need help with scripting you'll find tutorials here.

pdfscripting.com

Now the reason it's not so simple is that the "doc.submitForm" function doesn't indicate directly if the submit was successful.  It returns a true/false value, but it will return true even if the URL doesn't exist. This is because this function is Asynchronous. It returns before the submit is complete. The true/false value just means it started the submit. To truly detect a successful submit you need to receive a status value from the server on the return. A hidden field could be used for this. And you'll need to modify the server script to return a PDF data format. What is the server returning now?

A very simple solution might be to use two buttons, one for each action. Then you don't have to muck about with all this.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

LATEST

I handle this slightly differently. I package any script that I want to run only after a successful submit in an FDF that I return from the server. That way the PDF doesn't contain the script at all and only the server can trigger it. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines