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

Checkbox values -- updating database value to "no" when using CFpdfform / CFquery update

westonjeff
Registered: May 17 2010
Posts: 6

Sorry if this has been answered before, but I haven't been able to find answer,
 
I have a working report card system using PDF "templates" for six different grades, that get populated with data from mySQL tables.
 
Teachers log in and enter data every school quarter, and upon submission, data gets written to record for current student.
 
All was working well, until a teacher pointed out that "unselected" checkbox values do not save as such.
 
Going back to HTML forms' need to include hidden form fields / values for unselected checkboxes, I tried adding hidden instances of checkboxes using same field names, but Acrobat won't allow duplicate field name.
 
So, question is, how do I pass a "No" value for an AcroFrom checkbox, that gets carried into a ColdFusion processing page / query ?
 
Thanks in advance for any and all help.
 
Jeff

My Product Information:
Acrobat Pro 9.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
By default, a checkbox on an AcroForm has a checked value of "Yes" and an unchecked value of "Off". I imagine that in the CF script you are using cfinsert do move the Put(#FORM) data directly into the DB? And that the DB is not setup to handle the "Off" value?

The first thing you need to do is validate that the "Off" checkbox value is received correctly by the CF Script.

Next, there are a number of solutions.
1. Modify the DB to accept the values submitted by the form.
2. Modify the form, like you did for the HTML form, to submit the correct values. You can use radio buttons (both visible), or a second, hidden checkbox with the same field name. But some scripting will be needed to make sure that turning off the first check box, then turns on the second check box. This is a clunky solution, but easy to do if you know what you are doing.
3. Modify the CF script to translate the submitted value into what's needed for the DB. Use an explicit cfquery that uses a variable for the checkbox column. The cfquery will need to be proceeded by a script that converts the submitted value and places the result in the variable.


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

westonjeff
Registered: May 17 2010
Posts: 6
Quick message to thank you for your reply and explain a bit more.

The field type/length for checkboxes = char(6) so they should be able to handle either value.

I like #2, but I haven't been able to have two checkboxes with the same field name. What's the trick? When I try, Acrobat renames field name(s), adding #0 to original, and #1 to the duplicate field.

re: #3, I have a single CFquery processing script that takes all field names and concatenates them into one update statement line like such:

UPDATE ReportCards
SET ABSENCES_Q1='0',ABSENCES_Q2='1',FINEMOTORCOLORS_Q1='V',FINEMOTORCOLORS_Q2='V', FINEMOTORPRINTS_Q1='V', FINEMOTORPRINTS_Q2='V',FINEMOTORSCISSORS_Q1='V', FINEMOTORSCISSORS_Q2='V',MATHCOUNTING_Q1='109',MATHCOUNTING_Q2='110', MATHEFFORT_Q1='V', MATHEFFORT_Q2='V',MATHGEOMETRY_Q1='4',MATHGEOMETRY_Q2='4',MATHNUMERATION_Q1='4',

and so on for six grades. I'm no crazy about making six different update queries, because each grade has its own set of unique checkboxes, pulldowns, radio button, etc. fields.


So, if you have a chance, could you help me with . . . .

- How to have two checkbox fields with the same name?

- Direction to the information you're alluding to here:
Scripting will be needed to make sure that turning off the first check box, then turns on the second check box. This is a clunky solution, but easy to do if you know what you are doing.

Thanks again, Thom -- much appreciated!






thomp
Expert
Registered: Feb 15 2006
Posts: 4411
When you add a check box with the same name, Acrobat adds a #1 in the listing displayed in the Fields Navigation panel. This is the Widget Index for the field. It is not changing the field name. Check the names in the Properties Panel. Also try it out and see what happens. Actually, set the export values and then try it out with your CF script to see what happens. If this works for you, then ask me about the scripting.

However, I'm having a problem understanding why the form and CF script are not working as is? What's the deal with the DB column. If it's a text field, 6 characters wide, then why isn't the "Off" value being written into it. Is the "Off" value being received by the CF Script?


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

westonjeff
Registered: May 17 2010
Posts: 6
Thanks, Thom.

Right . . . "Off" values aren't being sent to CF processing page/query when boxes are unchecked, just like HTML form checkboxes.

My SQL update query updates database fields that have corresponding (submitted) form field names, so unchecked boxes are not included.

I'll do some testing, and debug dumps and get back to you -- thanks again!

westonjeff
Registered: May 17 2010
Posts: 6
After quite a bit of time toying with different scenarios, I'm convinced I'm unable to accomplish this task without some type of scripting.

Most promising idea was to duplicate existing checkboxes (same field names), making the new fields "hidden" with an export value of "no" and "check box is checked by default" selected.

No matter what I do (move fields around in document, in the "Widget Index" list, etc.), the "hidden" fields are not passed to the processing script -- even though they're checked by default.

Can you point me to some type of script help to add to the original checkboxes so there's a value being passed to the CF script if box is "unchecked"?

Thanks!!



thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok, I just did a test on the PDF submit. For expediency I used PHP on the server, but the results should be identical to what you see in ColdFusion.

The submit from the PDF was done using:

this.submitForm({cURL:"...", cSubmitAs:"HTML", bGet:true});

The query string received at the server did not contain values for text fields that were empty or for unchecked Checkboxes.

I added two check boxes with the same name to the PDF form. The export value on one check box set to "Yes", and the export value on the second checkbox export was set to "No". When the "No" checkbox was selected, a "No" value was received at the server, even when the "No" checkbox was hidden.

Everything appears to work just fine using the two checkboxes with the same name, one hidden and one visible.

So the question is, Are you sure the hidden check box is checked? I'd suggest unhiding them and doing a test to see what values are passed to the server.

Moving fields about in in the document and fields navigation panel will have zero affect. The only things that are important to submitting checkbox/radio button data are the field name and export value.

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

westonjeff
Registered: May 17 2010
Posts: 6
Thanks for your effort and time, Thom!

Your test results don't match mine.

I'm sure the hidden form fields are checked.

Your submit button code looks intriguing . . . as mentioned, I'm using Acrobat 9, with ColdFusion.

I tried revising way the form is submitted (include empty fields), requiring the checkboxes, yet the hidden field values don't get passed.

Thanks again, man!



thomp
Expert
Registered: Feb 15 2006
Posts: 4411
How are you performing the submit?

Take a look at the doc.submitForm function. It's got a lot of options.

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