user2296337
user2296337

Reputation: 29

Using Javascript To Turn PDF Forms Into Self-Correcting Assignments

I am a teacher and we are looking at going as paperless as possible. I learned (through searching here and asking a previous question) how to use Javascript to validate PDF form responses on an individual basis. I believe there are ways to validate an entire form prior to submitting it, but I haven't found out how to do that yet. The forms will be actually PDF documents, not web pages.

What my question is deals with that validation and submission. Is there a way to use javascript (or any other method) to:

  1. validate an entire form (which would be an entire assignment for a student to complete) with a click of the button?
  2. With that same click, submit the answers and "score" received to, say, a spreadsheet? My class has a website and domain that I can fully modify via cPanel to handle submissions, if I have to somehow set it up there.

Ideally, I want the submission and score, so students can't validate, change all their answers based on the validation, then submit a perfect assignment.

The alternative would be for students to fill out the form, validate, and have students print out their score. The only issue that I can see with that is with students reloading the PDF and changing their answers after validation.

Any insight or suggestions?

Upvotes: 2

Views: 272

Answers (1)

gn1
gn1

Reputation: 530

You can add JavaScript to the submit button and make it display the score and then submit the form field values to your website.

It is not fool proof. The Javascript error console in Adobe Acrobat/Reader may show leak information about your Javascript code. There are several PDF-processing tools that can extract JavaScript code from PDFs.

So, the best option is to have a simple submit button and have it submit the form field data to the server. On the server, you can have a script that evaluates the submitted form field data and send back a message to Adobe Reader in the form of a FDF stream. The FDF stream can contain the score.


  Response.ContentType = "application/vnd.fdf"
  Response.Write "%FDF-1.2" & VbCrLF & _
                 "1 0 obj<< /FDF << /Status (" & sAcroResponse & ") >>      >>endobj" & VbCrLF & _
                 "trailer" & VbCrLF & _
                 "<< /Root 1 0 R >>%%" & VbCrLF

The above script is in Classic ASP. The message (sAcroResponse) will be displayed within the Adobe Reader, not in a browser. You can adapt this script to whichever language that is supported on your web server.

Upvotes: 1

Related Questions