Skip to main content
Kim H Davis
Participating Frequently
October 7, 2018
Question

Conditional action on buttons

  • October 7, 2018
  • 2 replies
  • 536 views

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!)

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
November 6, 2018

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Joel Geraci
Community Expert
Community Expert
November 6, 2018

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. 

Bernd Alheit
Community Expert
Community Expert
November 6, 2018

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