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

Advise for JS in form

CanaryIslands
Registered: Apr 26 2010
Posts: 4

Hi guys!

I'm new to JS programming within pdf's, and also in this forum.

I've made a form, which is just a multi-line text, with a text-link acting as submit button.

I've made it from linux, using tex, pdfmarks and ghostscript. And the cgi on my server is a small c program I laid out for this.

Anyways, this all works, I can receive data sent from the pdf as HTML POST, and process it back in the server with no hassle.

The problem I'm facing has more to do with events in acrobat read, as I'd like the form to behave properly.

By using /K, /E, /Fo, etc.. actions within the text-field's annotacion (through the /AA dictionary), I can't reach my goal, which is as follows:

Having the text-field, I'd like it to show some text by default (i.e: "use this box to leave us a comment or message"). Once the user gives the field input focus (either by clicking on it of through the TAB key), the text dissapears, so it's not disturbing the user.

If he/she doesn't write anything and the field looses the input focus (note: just the input focus, no the just itself), and again, either by clicking outside the field or through the ESC key, my default text will get there again.

So my question is: First, is this achievable at all? if so, perhaps should I leave empty the /AA dictionary for that field, and place a script on that page's dictionary?

Advises on this would be much appreciated.

Regards,

My Product Information:
Reader 9.3, Unix/Linux
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Wow, that's quite an achievement. And yes, you can create the effect you want using JavaScript Actions in the OnFocus(/Fo) and OnBlur (/Bl) events

OnFocus:
event.target.value = "";

OnBlur:
if(event.target.value == "")
event.target.value = event.target.defaultValue;


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

CanaryIslands
Registered: Apr 26 2010
Posts: 4
Hi,

Thanks for your reply Thom!, or even better, double thanks!. I also saw you involved in a thread within this site while googling for "disable auto-rotate an center in a pdf".

What you quoted me is alrigth, but I couldn't achieve it so far. Acrobat seems to show some sort of erratic behaviour both in windows and unix, concerning focus and input focus handling as per what's stated on the specs. But I haven't looked at this in deep yet, perhaps I've missed something.

I wanted to ask something else, though.

I noticed yesterday that sending a form from within the acrobat embedded on the browser doesn't give same results as sending it from the standalone version.

When the form is sent from the former, is redirects you to the cgi, and so the very same tab or window where the reader is, gets replaced with whatever the output of the called cgi.

However, when the same form is sent through the standalone version, it expects a fdf in return (yes, even when the data was sent via HTML POST).

Before I think of writing or reusing some existing fdf reader/writer, I wanted to know if the data returned by the server could be used just for signaling form sending status.

Thus, in my case, I don't want fields' data back from the server to refill any of the fields, but just telling me if the form arrived succesfully at the server.

Perhaps by using a text or hidden field with a text like "message sent successfuly", or "error whie trying to send your message", depending on the answer the reader gets by parsing the returned fdf file.

Is this possible? As far as I understand, fdf files are mostly used for pre-fillin fields, more than to what I'm asking for, yet my application doesn't need of any feedback other than status of the arrival.

Regards,
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The data returned from the server does not have to be FDF. It can be any data format that Acrobat recognizes. And it does not have to contain any field data. You could send an empty data file. Only the fields that are referenced in the return data are affected. FDF used to be very helpful because it could contain a script to be run when Acrobat loads the return data. I used the script to display a popup message to the user on the status of the data submission. Unfortunately Acrobat 9 does not like FDF files because of security reasons. They have become very difficult to work with. It's better to return an XFDF file containing data for a single form field. Use this as you've suggested, to return status info to the user.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

NK-INC.COM
Registered: Apr 17 2010
Posts: 93
CanaryIslands wrote:
Hi,Before I think of writing or reusing some existing fdf reader/writer, I wanted to know if the data returned by the server could be used just for signaling form sending status.

Thus, in my case, I don't want fields' data back from the server to refill any of the fields, but just telling me if the form arrived succesfully at the server.

Perhaps by using a text or hidden field with a text like "message sent successfuly", or "error whie trying to send your message", depending on the answer the reader gets by parsing the returned fdf file.

Is this possible? As far as I understand, fdf files are mostly used for pre-fillin fields, more than to what I'm asking for, yet my application doesn't need of any feedback other than status of the arrival.

Regards,
Yes, FDF has the capability to send a status message along with the form data.

You would need to submit to a server-side script, where it could be parsed or e-mailed, and the status of that action, could be embeded in the same FDF form data, and sent back to the browser with all the fields filled in plus the status message. Or instead of sending back the FDF data, you can redirect the user to a web page, stating Success or Failure.

Only FDF has the capability to send status messages back to the user, not XDP, XML, or XFDF. However, this could be done by embeding some sort of Action Script, with a alert message.



For more information:
http://www.fdftoolkit.net/

Or:
Google "iText in Action"