Conditional action on buttons

Community Beginner ,
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

149

Likes

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

Conditional action on buttons

Community Beginner ,
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

150

Likes

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
Oct 07, 2018 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Nov 06, 2018 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Nov 06, 2018 0
Adobe Community Professional ,
Nov 06, 2018

Copy link to clipboard

Copied

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. 

Likes

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
Reply
Loading...
Nov 06, 2018 1