Stefan Cameron on Forms
Building intelligent forms using Adobe LiveCycle Designer

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.

Download Sample [pdf]

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
You can skip to the end and leave a response. Pinging is currently not allowed.

21 Responses to “Testing HTTP Submit Buttons”

  1. MikeMac on January 1st, 2010

    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

  2. Stefan Cameron on January 5th, 2010

    MikeMac,

    Thanks! :)

  3. Todd on January 6th, 2010

    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

  4. Stefan Cameron on January 6th, 2010

    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.

  5. Todd on January 19th, 2010

    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?

  6. Todd on January 19th, 2010

    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?

  7. Stefan Cameron on January 21st, 2010

    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”:

    myTable.access = "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…

  8. jdahl on February 4th, 2010

    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

  9. Stefan Cameron on February 11th, 2010

    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…

  10. Mano on March 10th, 2010

    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

  11. Stefan Cameron on March 14th, 2010

    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

    xfa.datasets.data.saveXML()
  12. Prince on March 18th, 2010

    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.

  13. John on March 23rd, 2010

    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?

  14. Stefan Cameron on March 25th, 2010

    @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.

  15. Stefan Cameron on March 25th, 2010

    @John,

    Please see my reply to Mano.

  16. John on March 30th, 2010

    can you link me an example?

  17. nabil on May 10th, 2010

    Hi,
    I want to know how to set the URL of the Submit button dynamiclally, using javascript with the event initialize for exemple.??

  18. Stefan Cameron on May 16th, 2010

    @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.

  19. jgrd on July 22nd, 2010

    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

  20. jgrd on July 22nd, 2010

    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

  21. Hasan on August 31st, 2010

    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.

Leave a Reply

Alternate Help: Unfortunately, I am not always able to keep track of older posts. Please feel free to continue discussions here or seek help at an Adobe Forum: Designer/Acrobat, Designer ES, Designer (v6-v8), XFA Forms, Acrobat, Reader.

If you're including scripts: To make sure your script and comment are properly interpreted, please make sure you replace any less-than ("<") characters with their character code equivalent: "&lt;" (without the quotes). Otherwise, your script and comment will inadvertently be cut short.