These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

SubmitForm with Parameter oJavaScript doesn't seem to work

CNitschke
Registered: May 25 2007
Posts: 12

Hello,

Using "submitForm" I'm posting data to a webserver when the user clicks on a button in a pdf-doc. Before and after uploading of the data I would like to check for certain values which were sent back by the webserver. Also I would like to temporary disable the "submit" button in order to prevent the user from clicking "submit" again, since the "submit"-window is not modal.

I know when the data transmission was started, I know when then transmission was SUCCESSFULLY ended. But I cannot find out when the transmission has timed out or was ended because of some other problem. In this case I have to enable the button again so that the user can try again.

So how can I find out if a data transmission is in progress or has ended?

I was playing around with the oJavaScript-Parameter in SubmitForm in order to store a value "Transmission in Progress" using the "Before" and a "Transmission Ended" using the "After", but I can't get it to work. Everything else works fine.

Here's the syntax:

this.submitForm({
cURL: "http://ts6/fdfgateway/response.asp",
aFields: new Array("here's the data"),
bEmpty: true,
oJavaScript:
{
Before: 'app.alert("before")',
After: 'app.alert("after")'
},
cSubmitAs: "FDF"
});

Nothing seems to get executed before or after the SubmitForm.

Has anybody ever worked with this parameter?

Regards
Christian

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Unless your PDF form has a field name "here's the Data" you will not get any data and should throw an error to your Acrobat JavaScript console or debugger.

// the name of fields to be submitted:
var sMayFields = new Array("fieldName1", "fieldName2", "fieldName3");
this.submitForm({
cURL: "http://ts6/fdfgateway/response.asp",
aFields: aMyFields,
bEmpty: true,
oJavaScript:
{
Before: 'app.alert("before")',
After: 'app.alert("after")'
},
cSubmitAs: "FDF"
});

George Kaiser

CNitschke
Registered: May 25 2007
Posts: 12
"here's the data" was only a "placeholder" for all the fields. Sending an receiving data is not the problem. This works great and doesn't throw any errors.

The issue is, that I would like to run code before and after submitting the data and that "oJavaScript" doesn't work the way I expected it to work.

I thought that before submission a popup "before" would appear and right after the submission a popup with "after" would show up. But there aren't any popups. After pressing the submit button, data gets sent to the webserver, data gets sent back to the pdf-doc (and gets displayed in the pdf-form) but there aren't any popups which would indicate that oJavaScript is executed.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Have you checked the JavaScript/Debugging console for error messages? By default Adobe has console notification of messages and errors turned off, but you can edit your preferences and turn it on, look under the “JavaScript” category.
You could use the “try … catch” statement to execute your code.
try {
this.submitForm({
cURL: "http://ts6/fdfgateway/response.asp",
aFields: new Array("here's the data"),
bEmpty: true,
oJavaScript:
{
Before: 'app.alert("before")',
After: 'app.alert("after")'
},
cSubmitAs: "FDF"
});
} catch (err) {app.alert(“Caught error: “ + err);}

George Kaiser

CNitschke
Registered: May 25 2007
Posts: 12
Thanks for the suggestion with the try-catch statement. I have tried this earlier, but it doesn't throw any error. Stepping through with the debugger isn't showing any error either.

After having read the description of the parameter "oJavaScript" again and again, I came to the conculsion, that this statement is not not be executed by the PDF-file which is submitting the data. I think that this statement just "passes" java-code inside the FDF which gets sent in order to be executed by a PDF-file which receives the "submitted" data.

Thanks for the help.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You are correct that the "oJavaScript" parameter is not executed by Acrobat on the submission. Acrobat executes the JavaScript in an FDF file that it's consuming, i.e., FDF sent back from the server script.

Storing data in the FDF is a brilliant idea! Change your server script to strip out the JavaScript in the submitted FDF, and then insert it into the FDF that's returned to Acrobat. This will give you a clue as to the success or failure of the submit.

I've used JavaScript in an FDF to give messages to the user and to make document changes that can't be done directly with FDF, such as document metadata. Take a look at the last example in this article:

http://www.acrobatusers.com/tutorials/2006/auto_insert_metadata

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script