Adobe LiveCycle Web Services Invocation - javascript

I have a simple form with a button (submit), two textbox fields and two hidden fields. On submit, I would like to pass in 3 parameters to a service using a WSDL URL. More specifically, I would like to pass in the ENTIRE form (including data entered in form) as a string (in xdp or pdf format) as one parameter and the values of the two hidden fields as two other separate parameters.
I am using Javascript to call the web service and pass in the parameters.
I have been struggling with trying to pass in the ENTIRE form as an xdp or pdf as a string parameter to call the web service. Is this even possible?
Thank you!

Yes. You can set that up inside the submit button settings, either sending form data as plain xml or xdp.

Well I couldn't figure out how to get the entire xdp. HOWEVER...
As it turns out I found out how to get the entire pdf.
You MUST get the base64 encoding in order to get the entire pdf. For some reason if you do not encode the Collab.documentToStream into base64 it doesn't return the entire pdf (only a small section of it). This is my solution:
var documentString = util.stringFromStream(SOAP.streamEncode(Collab.documentToStream(event.target), "base64"));
From that you can decode the string from base64 to ansi on the server side which should give you the entire pdf to be stored or opened.
I will accept this as an answer to my own question. I edited my original question for clarification.

It is bad practice to pass this in the URL. If you want to use a String, it should be passed in the body of the request (i.e. a REST endpoint that accepts a string input). Passing this in the URL could eventually reach the URL length limit if the form or data is long enough.

Related

Download file via POST in one request with JavaScript

Sometimes when making an HTTP request to download a file (e.g. PDF, XLSX, etc.) from the own webserver, it is necessary to use the HTTP method POST, because it requires dynamic input data. I have been trying different ways to reduce that to one single HTTP request for best performance, but could not succeed.
As JavaScript with the XMLHttpRequest object (AJAX) can not "download" files, I guess it requires an HTML workaround. The only working solution I found for that case is generating a form element wrapping input elements containing the data. I could not find a way how to send boolean values via this, as AJAX is able to. That would mean: it is not suitable for a standardizable implementation.
My question is: How can I download a file via one POST request which can include boolean values (JavaScript)?
In case it is important: The backend system I use is Ruby on Rails
As #Pointy mentioned, boolean values are always translated to strings in HTTP communication. I was wrong about that in my question. That means, converting a JavaScript JSON string or a classic object to an HTML form (then submitting and deleting it) works!
Actually sending an AJAX request and then manually triggering a link click to the generated file has the advantage of being able to use a progressbar.

Passing large amounts of data from one page to another without POST?

I'm using a web server framework which works with only GET requests, at the moment I'm trying to pass a large amount of data, that is the text content in a textarea which comes from user input, into another page which echoes the user's input.
I've attempted Querystrings but I end up receiving the error "Requested URL too long".
Any suggestions as to what method I should use?
If you can only send data encoded in GET requests, then you will have to break up the request and send it in multiple parts.
You could either use Ajax or store the entire set of data in localStorage and fetch each chunk in turn as the page reloads.
One approach would be to make a request to an end point that allocates you a unique ID. Then send a series of requests in the form: ?id=XXX&page=1&data=... before closing it with ?id=XXX&total_pages=27 at which point you assemble the different pieces on the server.
This way lies madness. It would be much better to add POST support to your framework.
Try using Javascript Cookies.
you can store the textarea value there and then read it in another page (or wherever you want).
Here's a tutorial
http://www.w3schools.com/js/js_cookies.asp

How to get POST contents before form submits using javascript

So, I know that when I submit a form whose method is POST that the server receives the contents of that form and then processes them accordingly, and then returns a page with the desired content. What I am trying to learn is what exact query url is being passed to the server side script when I submit a form on a website that does not belong to me. The reason I want this query string is so that I can make use of the server side script programatically with my own data. There is no public API served by this website, but I would like to formulate my own.
So my question is, is there a way to intercept the POST as a query string URL? Perhaps by using a javascript console in browser?
I know I can look at the source code for the page and find the names/values of the form fields. However, there also happens to be a hidden field on this page whose properties are set by javascript during validation at submission time. How should I go about this?
You can use an extension for intercept the data : Tamper Data on FireFox
https://addons.mozilla.org/fr/firefox/addon/tamper-data/
You can intercept and modify all headers requests

Save the client HTML content back to the Server as a HTML file

I want to create an HTML form on the Server. When the client completes the form and clicks submit, I want to be able to save HTML form and data in a single HTML file on the server.
The best suggestion I have seen is using JavaScript. Use a client side script that on click will save the document.InnerHTML to a var that can then be submitted back to the server.
Is this the best approach, or is there an easier way?
Even though I have no idea why you want to save the whole html code because I'm sure there will be parts that are the same for every user and you will be wasting memory, but ok.
So there are two ways to do this:
1. is javascript as you said
2. would be to put all the generated html code into a hidden form input (already on server side)
the first one seems more comprehensive and this is what I would do but the second one would also work for users with js disabled.
I wouldn't really recommend this way, because I'm still a huge fan of saving data in a database, but here's a general outline of what to do:
User fills out the form and submits.
Server-side code executes a method:
a. String holding the template for your HTML page with placeholders for the fields.
b. Use String.Format to put all the user input into the correct places.
c. Create a file, write the string to the file, and save.
d. Return file name to user.
HTML files are not that large, but still you risk using up your hard drive space. Also, you need write permissions which introduces security risks.
Going the database route:
1. User fills out the form and submits.
2. Server-side code saves the data to a database, and returns a link (with querystring string of ID and possibly a user id to help with security) to the user.
3. Whenever the user goes to the link, the server-side code repopulates the form with the ID passed.

Extract data from HTML form

I've got some Javascript which gets the HTML for a form from the server via an XMLHttpRequest, and displays the form on the page.
What I'd like to be able to do is extract the data which would be sent via POST if the form was submitted, then send it via another XHR. The tricky bit is that the form could contain different elements of different types.
Is there a way of doing this without having to inspect each element on the form, determine its type, manually extract the data based on the type, and build it all into a query string?
Is there a way of doing this without having to inspect each element on the form, determine its type, manually extract the data based on the type, and build it all into a query string?
No, there isn't, but there are prewritten libraries that have the code for that already written. e.g. jQuery serialize
Note that if you want to make a POST request, then the data should go in the request body, not the query string.

Categories