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

Submitting Information to a SQL Database

bradh
Registered: May 8 2009
Posts: 8

Hello,

So, I have this form that I am trying to get the data submitted to a SQL Database. I have the ODBC connection created and named EmpSep. I have the code written in my form. I keep getting this error:

page1.Subform1 has no properties
2:XFA:form1[0]:page1[0]:Button2[0]:docReady
GeneralError: Operation failed.
XFAObject.setAttribute:3:XFA:form1[0]:page1[0]:Button2[0]:click
This operation violates your permissions configuration.

I have been added to that Table with full access. I am not even getting the warning box that shows me I am submitting something to the Database. Here is my "Button's" click event...

xfa.sourceSet.DataConnection.nodes.item(1).query.setAttribute("text", "commandType");
xfa.sourceSet.DataConnection.nodes.item(1).query.select.nodes.item(0).value = "INSERT INTO problems(description)VALUES('"+AllFields.rawValue+"')"
app.alert(xfa.sourceSet.DataConnection.nodes.item(1).query.select.nodes.item(0).value);

//now connect to DB and get a record
xfa.sourceSet.DataConnection.open();

Does anyone have any suggestions or see something that I am overlooking?

Thanks,
Brad

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
This is really the wrong way to go about inserting a record into a DB. The 2nd reported error has to do with accessing the XFA node. It isn't about the DB or the connection. You are not allowed to modify this part of the SourceSet model directly. The first reported error doesn't have anything to do with the DB connection. It's about a bad subform reference.

The first thing you need to do is validate that you can connect to the DB and read data out of it. If this works out successfully. Then use the "addNew()" function to insert data into the DB. If this works then you can start working on the real form. If you want the SourceSet structure to perform different operations than what is setup from the DataView tab. Then you'll need to modify the SourceSet XML directly. But be careful. you'll need to know exactly what you are doing.

Take a look at Stefan Cameron's blog, http://forms.stefcameron.com/, he knows more about this stuff than anyone. He has a few blog entries on DB connections.

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.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

bradh
Registered: May 8 2009
Posts: 8
I know that I can access the data....What I have is this...I have form with 15 fields. I want all 15 fields to submit to on column in a sql database. I have taken these fields and written code to update them all to a hidden field. From there I am binding the hidden field to my column in sql. Here is the entire script of my submit button...


form1.page1.Button2::click - (JavaScript, both)
form1.page1.AllFields.rawValue = form1.page1.TextField2.rawValue + " " + form1.page1.TextField3.rawValue + " " + form1.page1.TextField4.rawValue + " " + form1.page1.TextField6.rawValue + " " + form1.page1.TextField7.rawValue + " " + form1.page1.TextField8.rawValue + " " + form1.page1.TextField9.rawValue + " " + form1.page1.DropDownList1.rawValue + " " + form1.page1.CheckBox1.rawValue + " " + form1.page1.CheckBox2.rawValue + " " + form1.page1.CheckBox3.rawValue + " " + form1.page1.CheckBox4.rawValue + " " + form1.page1.CheckBox5.rawValue + " " + form1.page1.CheckBox6.rawValue + " " + form1.page1.CheckBox7.rawValue + " " + form1.page1.CheckBox8.rawValue + " " + form1.page1.CheckBox9.rawValue + " " + form1.page1.CheckBox10.rawValue + " " + form1.page1.CheckBox11.rawValue + " " + form1.page1.CheckBox12.rawValue + " " + form1.page1.CheckBox13.rawValue + " " + form1.page1.CheckBox14.rawValue + " " + form1.page1.CheckBox15.rawValue + " " + form1.page1.CheckBox16.rawValue + " " + form1.page1.CheckBox17.rawValue + " " + form1.page1.CheckBox18.rawValue + " " + form1.page1.CheckBox19.rawValue + " " + form1.page1.CheckBox20.rawValue + " " + form1.page1.CheckBox21.rawValue + " ";

xfa.sourceSet.DataConnection.nodes.item(1).query.setAttribute("text", "commandType");
xfa.sourceSet.DataConnection.nodes.item(1).query.select.nodes.item(0).value = "INSERT INTO problems(description)VALUES('"+AllFields.rawValue+"')"
app.alert(xfa.sourceSet.DataConnection.nodes.item(1).query.select.nodes.item(0).value);

//now connect to DB and get a record
xfa.sourceSet.DataConnection.open();


form1.page1.Button2::docReady - (JavaScript, both)
var oNodes = page1.nodes; for (var i=0; i < oNodes.length; i++) {if (oNodes.item(i).className == "field") {if (oNodes.item(i).rawValue == null) {oNodes.item(i).rawValue = " ";}}}
var oNodes = page1.Subform1.RadioButtonList.nodes; for (var i=0; i < oNodes.length; i++) {if (oNodes.item(i).className == "field") {if (oNodes.item(i).rawValue == null) {oNodes.item(i).rawValue = " ";}}}Do you have an example script that I could use for the submit portion?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Using hidden fields to connect to the DB is a good idea.

Here's some code that uses the standard "addNew()" and "update()" functions to insert data
xfa.sourceSet.DataConnection.open();xfa.sourceSet.DataConnection.addNew(); ... Modify hidden fields bound to the connection ... xfa.sourceSet.DataConnection.update();xfa.sourceSet.DataConnection.close();

In the Button2:docReady code it would be much easier to use the "xfa.layout.pageContent()" function to find all the form fields. Since it looks like the code is just resetting the fields it would be even easier to just use the "xfa.host.resetData()" function. Have you tried usin the form's Initialize event.

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.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

bradh
Registered: May 8 2009
Posts: 8
Since I can't get this to submit directly to my database, how difficult is or is it possible to submit it to PHP(or some type of service) running on a webserver and have the webserver do the work for me? Is this the better option anyways? I plan on publishing this on our intranet for numerous users to use. If i am thinking correct, by submitting directly to the database I would have to create an ODBC connection on every computer that would be using the form. If is submit it to a process running on a webserver I only have to do the connection one time. Is this correct? I am just starting out on the programming side things and was courious as to which process would be the best to submit it to.

Thanks
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you are a PHP programmer then it's no problem at all to submit to a server script. Just add a regular form button to the form and make is a submit button. Set the data type to XML. The XML is in the body of the HTTPRequest that gets sent to the PHP script. The script needs to acquire the body data and parse the XML. From there it's just a matter for writing the data into the DB. You also have to return something to Acrobat in the HTTPResponse. I usually send back an FDF with a single JavaScript action in it. The JS displays an alert box letting the user know what just happened. There are some posts on this forum that provide some PHP code for doing this.

You don't need to do anything with ODBC. It's just like submitting data from a web page.

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.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

asrauf
Registered: Jul 13 2009
Posts: 5
I have used the same code...It's working like display data from database..
But what i want to do....i need to store the data into sql database....

I need to do INSERT command.....please advice.

please review my below code...is it correct code...??

I have only 4 textbox and 1 submit button.

----- form1.#subform[0].Header.btn_submit::click: - (JavaScript, both) -----------------------------

form1.page1.AllFields.rawValue = form1.page1.TextField1.rawValue + " " + form1.page1.TextField2.rawValue + " " + form1.page1.TextField3.rawValue + " " + form1.page1.TextField4.rawValue + " ";

xfa.sourceSet.DataConnection.nodes.item(1).query.setAttribute("text", "commandType");
xfa.sourceSet.DataConnection.nodes.item(1).query.select.nodes.item(0).value = "insert into check_request(emp_name, title, department, phone) values('"+AllFields.rawValue+"')"
app.alert(xfa.sourceSet.DataConnection.nodes.item(1).query.select.nodes.item(0).value);

//now connect to DB and get a record
xfa.sourceSet.DataConnection.open();


----- form1.#subform[0].Header.btn_submit::docReady - (JavaScript, both) ---------------------------

var oNodes = page1.nodes;
for (var i=0; i
asrauf
Registered: Jul 13 2009
Posts: 5
please review my below code...is it correct code...??

I have only 4 textbox and 1 submit button.

----- form1.#subform[0].Header.btn_submit::click: - (JavaScript, both) -----------------------------

form1.page1.AllFields.rawValue = form1.page1.TextField1.rawValue + " " + form1.page1.TextField2.rawValue + " " + form1.page1.TextField3.rawValue + " " + form1.page1.TextField4.rawValue + " ";

xfa.sourceSet.DataConnection.nodes.item(1).query.setAttribute("text", "commandType");
xfa.sourceSet.DataConnection.nodes.item(1).query.select.nodes.item(0).value = "insert into check_request(emp_name, title, department, phone) values('"+AllFields.rawValue+"')"
app.alert(xfa.sourceSet.DataConnection.nodes.item(1).query.select.nodes.item(0).value);

//now connect to DB and get a record
xfa.sourceSet.DataConnection.open();


----- form1.#subform[0].Header.btn_submit::docReady - (JavaScript, both) ---------------------------

var oNodes = page1.nodes;
for (var i=0; i
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I think you are over complicating things. Whats the problem with using the standard:

xfa.sourceSet.DataConnection.addNew():

and

xfa.sourceSet.DataConnection.Update():

Is there some compelling reason you need to do the SQL Insert?

What is the point of the "AllFields" value?


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

Tech264
Registered: Apr 4 2008
Posts: 111
Just wanted to add my 2 cents in here, I'm wanting to do the same thing but I thinking of going through Adobe Flex via PHP to make my life a lot more easier.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The Built-in DataBase connection in LiveCycle forms is for using an OLE DB driver to connect the form to a local database. Windows comes with all kinds of OLE DB drivers and this setup is easy to use. Mr. asrauf is using this DB connection in a very non-standard way. It looks complex because that's the way he's making it.

Using Flex and PHP is a different thing. Right off, you can't place a Rich Media Annotation in a LiveCycle form. But regarless, using this technology requires crossing several technolgy boundaries, which increases the complexity and difficulty of implementation. PHP is a server scripting technology. If you want to connect a PDF form to a DB through a Server Script then there is a much, much, easier and more direct way to do it than through Flex.

So, what is it you are trying to do? And how are you thinking Flex fits into the picture?

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

Tech264
Registered: Apr 4 2008
Posts: 111
I want to have a company website in place for 15 different locations. All the employees will have access to their department forms that was done in LiveCycle. They will fill out the forms using the basic Adobe Reader. What I'd like to do is once they've completed the form they can hit a submit button that will enter all the information in a database. Whether it be access, sql or mysql. Later on if they've not finished filling out their work they could go on the web do a search for their client pull up the form continue working and re-submit it with the new changes.

I've done this about 4 years ago with Infopath but I like the way I can make the forms more presentable with LiveCycle.

So I figured Adobe Flex 3 would be the ideal choice since it does a lot of the PHP coding for you. You can see a table of all your submitted data and you can search. However, the only thing I don't know is if once you do a search will it pop up your PDF form.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I'm unclear about how you are planning on using LiveCycle with Flex. Can you elaborate?

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

Tech264
Registered: Apr 4 2008
Posts: 111
Actually was more incorporating it with LiveCycle Data Services.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ahh, so you have the Servers. I thought so. You should have said this up front. LC Data Services is not a solution that is availible to most people. So it is not appropiate to suggest it, especially since this wasn't explained up front. You really need to be explicit about what you are doing.

The topic was about using the standard LC Form connection to a local data base, not a DB on a server, no servers involved. Hence, your first post gave the impression that there was some way to use Flex and PHP to connect an LC form into a local DB and that since you didn't give any detail that it must some how be obvious or self evident. None of which is not true. You can't use flex to connect an LC form into a DB. And if you're going to use PHP on a server you can just use a standard form submit.

Your post is off topic and misleading.
Please don't do it again.

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

Tech264
Registered: Apr 4 2008
Posts: 111
You're right and I apologize. I did make it confusing without mentioning at first about the data services. As we say in NY, "My Bad!"
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
No Worries, Please keep posting and answering question when possible. We need all the help we can get:)

cheers,
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

asrauf
Registered: Jul 13 2009
Posts: 5
Is Digital signatures works in normal PDF??

Also I tried lot for emails submit button only sent .XML format not PDF.

I want to send PDF format only.

But IF installed in Acrobat professional everything works perfect. For normal users PC doesn’t have Acrobat professional.

1. I need to do email submit button as a PDF format.
2. Digital signatures for all users.

Please advice.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If the PDF is Enabled with Reader Rights, then it can submit the entire PDF and be signed by a user with Acrobat Reader.

Use this menu item: "Advanced > Enable Usage Rights in Adobe Reader..."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

asrauf
Registered: Jul 13 2009
Posts: 5
It works perfect. Thanks alot.

Regards
Asrauf