Testing HTTP Submit Buttons
While recently helping a few people with some issues related to HTTP submissions from XFA forms, I ended-up creating new Data Service that helps with testing HTTP Submit Buttons.
The service is quite simple: It displays what you submit to it. Since Designer’s “PDF Preview” tab is actually an instance of Internet Explorer hosting a PDF version of the form you’re previewing (a temporary PDF if your form is saved as an XDP or is new), the results are conveniently displayed within the tab itself after clicking on the submit button.
To use the service, simply use either an http submit button (or a regular button with its “Object palette > Field tab > Control Type property” set to “Submit”) and set its URL to:
http://forms.stefcameron.com/services/http-submit-test/
The idea is to use this service as a means to test/debug your forms before spending time writing the actual server code that will receive the data. You can also use it to ensure that you are submitting the correct data to a third-party service (for which you don’t control the server-side code).
Choosing a Submit Format
HTTP submissions can be made in various formats: XML, XDP, URL-encoded (HTTP post), and PDF. If you are using Reader instead of Acrobat, you will not be able to submit in PDF format unless you have enabled this ability using LC Reader Extensions.
The most important difference amongst the formats is that repeating data sets cannot be submitted using URL-encoding (HTTP post). This is due to the way the data is submitted: In HTTP post directives, data is submitted in “name=value” pairs. Since repeating data sets involve hierarchy and duplicate data node names, only the last instance of the repeating set will be submitted.
To submit repeating data sets, you must choose either XML, XDP or PDF as the data format.
Sample Form
The following sample form demonstrates the use of the HTTP Submit Test service.
The form has a typical address block as well as a table to demonstrate both static and repeating data sets. Use the submit buttons to try submitting in different formats (XML, XDP, PDF, URL-encoded). Notice how only the last table row is submitted when using the URL-encoded (“post”) submit button.
Minimum Sample Requirements: I created this sample using Designer 9.0 and Acrobat 9.2 however it should work fine back to Acrobat 7.0.5.
Posted by Stefan Cameron on December 16th, 2009
Filed under Data Binding,Debugging,Tables,Tutorials,XFA
Both comments and pings are currently closed.
This kind of example is a great resource for learning and using LCD – thanks Stefan! (and may you continue to produce these helpful bits and bobs throughout 2010 – we neede them!)
Mike
MikeMac,
Thanks! 🙂
In your example for the HTTP Submit buttons, there is a table that you can add rows and delete them, How do I set that up in LiveCycle? I am working on a form for our field techs to make everything digital, but that is the one thing that is holding me back from completing this task. I have multiple tables that I need to make but don’t need all the rows unless the tech needs them to add new information. Please help me out. Also I am new to LiveCycle so the simpler the terminology the better. Thank You
Todd,
I’ve got just the right tutorial for you: Expandable Table with Totals. It should tell you everything you need to know about making dynamic tables in which you add/remove rows.
That worked for me, I have another question, I am setting up new form to have a submit button to e mail. I figured out to get the new email to come up and send it but on the receiving end I would like to have the button be invisable and to have the form be locked, any advise?
Stefan,
I forgot to mention that I have the script, but it does not seem to work for me, maybe I am missing something
for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {
var oFields = xfa.layout.pageContent(nPageCount, "field");
var nNodesLength = ofields.length;
// Set the field property.
for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
oFields.item(nNodeCount).access = "readOnly";
}
}
{this.presence = "hidden";
}
I am improving on my Livecycle skills, just need to get this script writing down. I have 2 tables that have text boxes in the tables to be able to add information. Also I have it saved dynamic so i can use the add and remove button. Any Advise?
Todd,
If you’re using Designer 8.2.1 with support for XFA 2.8 (Acrobat/Reader 9.0), you can disable all fields in a table simply by setting the table’s access property to “readOnly”:
Otherwise, your script is OK with the following exceptions/notes:
1. The line “var nNodesLength = ofields.length;” has a typo in it where “ofields” should be “oFields”.
2. The last two lines don’t make sense to me.
3. Since you’re using xfa.layout methods, you need to execute this script in a LayoutReady event which is fired once the form’s layout has been generated. Otherwise, the field count will be incorrect (likely 0) and your script won’t loop through anything…
Hi, my http submit button works, but I am trying to submit a contact form to google sites. How can I do this or do I need to arrange a server? Can you recommend a free location to submit this form to, so I can easily access visitor comments/contact info?
Best regards
jdahl,
It sounds like you want to submit data from your form via HTTP but you want to capture the submission. If so, you’ll need your own web server for that, like a hosting service and a domain name. I don’t know of any free ones you can use…
Hi,
I have a PDF form that I should submit to a URL. The server should send me back a flag indicating the operation, say if the server successfully saved the PDF contents. The question is, how do i get back that flag within the PDF form so that I can do further processing based on the result. Right now i am getting an error message “Cannot handle content type: ”
Any help is appreciated.
thanks
Mano
Mano,
When are you getting this error message?
You might want to consider using FormCalc’s Post() function which would let you post the form’s data to a URL of your choice.
You can read about Post() on page 1044 of the XFA 2.8 specification.
You can get the form’s data by calling
My problem is that I need the CGI script to be able to handle the form I submit to url. I also need the steps to take to accomplish this. Thanks a million.
I have the same problem of Mano!!!!
When i click from Reader on submit button I’m i am getting the error message “Cannot handle content type:… ” But If open the pdf inside my browser it works!!! Any suggestions?
@Prince,
I don’t know how to write a CGI script but when you submit XML data from a form, the server should receive a header indicating the type of content that is being posted. If your form submits XML, the content type will be “application/xml”. If it submits a PDF, it’ll be “application/pdf”. Your script should handle the formats as you see fit.
@John,
Please see my reply to Mano.
can you link me an example?
Hi,
I want to know how to set the URL of the Submit button dynamiclally, using javascript with the event initialize for exemple.??
@nabil,
This is very similar to customizing an email submit button. See the part where the sample script sets the “target” attribute of the <submit> node in the button’s Click event.
Hi,
thanks for your tutorials and all services your offer to the Pdf forms user community.
I’m trying to send the content of a Pdf form (XFA dynamic) which is based on an Xml Schema to a local Alfresco ECM. I’m facing a problem as I don’t know how to get the xml data on the server side. I’ve posted on http://forums.adobe.com/community/livecycle/livecycle_es/livecycle_designer_es forums about it, but with no answer (as yet).
I know that if I use a url encoded request, all form fields will be flatten and written into the url, and I can get them for rebuilding the xml… But this would be nonsense. If I send the content as Xml or as XDP, I don’t know where the xml content is. This might be simple I guess…
Hope you have time for a tip!
Thanks,
Best regards,
jgrd
I’ve found a solution about the HTTP POST problem. The form content (that is xml) is accessible thru an object in Javascript called requestbody. The property requestbody.content contains the actual xml part of the form.
Sorry if this message was a bit out of the way of this thread.
jgrd
HELP: I have a form with a submit button. When I submit the form in Adobe Reader 9.3.3 I expect a reponse in a browser but instead I get an error message “An error occured during the submit process. Unknown failure.” When I try the httpsubmittest.pdf I get the response in the browser. I have tried to make my form as close as possible to yours and also tried putting my url in yours but it does not work. I am using ColdFusion 9.0. I have tried setting response content type to “application/xml; charset=utf-8” to no avail. Thanks.
Hi,
I have a XFA form which can be submitted using HTTP form submission. I am dispaying this form during an application flow on my website. Submitting the PDF shows a success page to the user with a link to download read-only format of the PDF which they have submitted.
Everything works fine if the PDF opens in browser. If the user unchecks ‘Open PDF in browser’ option from Adobe Reader, then I would like to close the PDF opened in Adobe reader once the user submit the PDF by clicking the Submit button and refresh the opener browser window with resultant page.
Can I get a handle of the opener browser window from PDF?
If I close the PDF using event.target.closeDoc(), the refresh of the browser id not happening. Is it possible?
Refresh of the browser works fine if I didnt close the PDF.
Please find some time to answer this.
THanks
Neeraj
@Hasan,
First, to get a response in the browser, the PDF must be loaded in a browser (note that when previewing forms in Designer, you are actually using Acrobat/Reader loaded in Internet Explorer). If you submit from Acrobat/Reader loaded standalone, Acrobat/Reader will attempt to create a PDF from the response. Since Reader cannot create PDFs, you’ll get an error (though admittedly not a “submit failed” error).
Since your form works fine when submitting to my test service as opposed to yours, it sounds more like an access issue outside the form itself — like your computer cannot see your service. When it comes to access, the first thing that comes to mind is the possible need for a cross-domain policy file (i.e. crossdomain.xml) that gives permission for access to your server from various domains. I have one that specifies that all domains have access (and it’s located in my server’s root):
@Neeraj,
Sounds interesting but I think you’re venturing into uncharted territory…
Stefan, I meant to say that when I submit your form from Reader the response comes back to the browser. And that is how I want my form to behave but with my url. I put my url in your HTTPSUBMITTEST.pdf form and that gave an error. If you say that I have to open the form in a browser to get the response in a browser then how come the HTTPSUBMITTEST.pdf when sublitted from Reader gives a response to the browser? I tried from 2 different PCs and it works both places. I figure there is something in your server script that propmpts the browser to open and display the response.
@Hasan,
I’m afraid there’s nothing I can think of that I did special in my server script that prompts the browser to open.
Based on my testing, if you open my sample “HttpSubmitTest.pdf” form in Reader or Acrobat outside the browser (i.e. right-click on the link to the sample, save it to your desktop and double-click the PDF file to open it), the response will come back to Reader or Acrobat (and will fail in Reader).
If you load my sample form in a browser (i.e. by simply clicking on the link to the sample, causing the PDF to be loaded in the browser via the Acrobat/Reader plugin), the response will come back in the browser.