Saving Data To Database From XSLT Options
VirtualRichard
Posted: Wednesday, August 06, 2008 11:31:49 AM

Rank: Fanatic

Joined: 9/17/2007
Posts: 265
Location: London, UK.
This question is related to this post but I've belatedly realised this won't work for me.

I have a form that adapts itself according to where the request came from on the site. Even the recipients might change depending where you came from. The form fields certainly do.

I need to save whatever information is provided in this form to the database so admins can query it later. I also need to send selected form data by email but that's easy.

Without using Autoforms, etc. how do I do this? Which table would I save to? Is there an 'easy' way via XSLT or do I need to create my own user control to handle the input?

Last thought, any way of getting that data into the umbraco admin dashboard?

Thanks,

Richard

2 * 3 * 3 * 37 : The prime factorisation of The Beast.
imayat12
Posted: Wednesday, August 06, 2008 12:08:38 PM

Rank: Addict

Joined: 7/19/2006
Posts: 670
Location: Preston, UK
Richard,

You can create your own table and save the data there after the form post . Create your own .net form and save the data to the table.

In order to get quick and dirty hack into the admin section to administer data in the table i would recommend building a data layer using subsonic and using the scaffold control on a user control to give you quick admin operations then add the control via dashboard xml into one of the existing sections. We have done this for a client that needed to admin volunteer and study applications these forms were quite big also they wanted search due to volume of data. Subsonic really speeded up the process.

Regards

Ismail

Level 2 certified. If it aint broke dont fix.
LostInSwiss
Posted: Wednesday, August 06, 2008 2:15:11 PM

Rank: Devotee

Joined: 3/31/2007
Posts: 66
Location: Switzerland
As Ismail mentions you need to create your own table.
Though if you don’t want to get your hands dirty with .Net (but know SQL) then consider jespers umbracoSQL
, you can execute SQL statements via xslt with this extension. Its not a package but not too hard to setup.

I will checkout Ismail's solution myself sounds interesting.


Alec
VirtualRichard
Posted: Wednesday, August 06, 2008 2:55:34 PM

Rank: Fanatic

Joined: 9/17/2007
Posts: 265
Location: London, UK.
I used Jesper's umbracoSQL and that works great on my custom table.

Doesn't umbraco already have a data layer you could use?

Richard

[edit] HA! Constructing SQL in XSLT... Don't do it... just say no! Argh... If you must, do it like this:

Code:
<xsl:variable name="A" select="umbraco.library:RequestForm('A')"/>
<xsl:variable name="B" select="umbraco.library:RequestForm('B')"/>

<xsl:variable name="exp">
    <xsl:text>INSERT INTO tablename (A, B) VALUES('</xsl:text>
    <xsl:value-of select="$A"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="$B"/>
    <xsl:text>')</xsl:text>
</xsl:variable>

<xsl:variable name="saveForm" select="jesper.sql:SQLExecuteScalarInt($exp)"/>


Jesper's handy little utility might want updating to use stored procedures?

2 * 3 * 3 * 37 : The prime factorisation of The Beast.
jesper
Posted: Wednesday, August 06, 2008 9:20:31 PM

Rank: Administration

Joined: 7/25/2006
Posts: 425
Location: vipperoed, denmark
VirtualRichard wrote:
I used Jesper's umbracoSQL and that works great on my custom table.

Doesn't umbraco already have a data layer you could use?

Richard

[edit] HA! Constructing SQL in XSLT... Don't do it... just say no! Argh... If you must, do it like this:

Code:
<xsl:variable name="A" select="umbraco.library:RequestForm('A')"/>
<xsl:variable name="B" select="umbraco.library:RequestForm('B')"/>

<xsl:variable name="exp">
    <xsl:text>INSERT INTO tablename (A, B) VALUES('</xsl:text>
    <xsl:value-of select="$A"/>
    <xsl:text>','</xsl:text>
    <xsl:value-of select="$B"/>
    <xsl:text>')</xsl:text>
</xsl:variable>

<xsl:variable name="saveForm" select="jesper.sql:SQLExecuteScalarInt($exp)"/>


Jesper's handy little utility might want updating to use stored procedures?


That doesn't look good. It's too easy for the evilminded to hack your data using some SQL injects. Let's just say input field b had the following value:

dummy');delete from anytablename;insert into tablename (a,b) values('yes','no

Result: all is gone :-)

You'll need to add some checking on the values before inserting them into your sql expression.

Personally I mostly use jesper.sql to add/update internal values.


kindly,
Jesper

webbureau jesper.com doing webdesign / development / umbraco implementations / 2007&2008 MVP / umbraco certified
VirtualRichard
Posted: Thursday, August 07, 2008 10:40:08 AM

Rank: Fanatic

Joined: 9/17/2007
Posts: 265
Location: London, UK.
Sure there's checking going on but I'm not going to post that code ;) That was just a quick fyi.

Richard

2 * 3 * 3 * 37 : The prime factorisation of The Beast.
Leads
Posted: Thursday, November 06, 2008 3:54:55 PM
Rank: Enthusiast

Joined: 9/11/2008
Posts: 34
Location: Dhaka
Hi Richard,

Will Jesper's umbracoSQL work for any sql statement.
Like select statement.

Thanks
Ismail
bhunt
Posted: Thursday, November 06, 2008 6:33:42 PM
Rank: Newbie

Joined: 11/5/2008
Posts: 5
Location: Texas
One other idea on getting the data into the umbraco dashboard.

1. Create a new user control (.ascx) file in Visual Studio.
2. Open the "server explorer" and add a data connection to your database.
3. Once you have the data connection, you can browse the tables in the database. From the server explorer, click and drag the table itself onto the design view of the new user control you created.

Visual Studio will add a grid view to the control and write all the basic CRUD sql statements for you. (Technically, VS will not write the create SQL as you need an input form for that.)

And in the designer, you can click on the little quick links and tell it to automatically sort, delete, page the data etc.

Then you can edit your dshboard.config file to reference the new user control.

One note: when you drag and drop from the server explorer, VS might try to add a new connection string to your web.config. So you might examine the code that it created in your control and make sure it points to your usual connection string.
VirtualRichard
Posted: Monday, November 24, 2008 8:57:42 PM

Rank: Fanatic

Joined: 9/17/2007
Posts: 265
Location: London, UK.
Leads wrote:
Hi Richard,

Will Jesper's umbracoSQL work for any sql statement.
Like select statement.

Thanks
Ismail


Better late than never...

You can fetch rows from the database into a variable:

Code:
<xsl:variable name="sqlstuff" select="jesper.sql:SQLXml('SELECT * FROM tableName')"/>

<xsl:for-each select="$sqlstuff/tableName">
    <xsl:value-of select="@ColumnName"/><br />
</xsl:for-each>

Richard

2 * 3 * 3 * 37 : The prime factorisation of The Beast.
Ig_p118
Posted: Friday, November 28, 2008 4:07:00 PM

Rank: Fanatic

Joined: 7/21/2006
Posts: 315
Location: Salerno - Italy
I prefer to write my usercontrol in Vs.


Red Consulting s.a.s - Umbraco from v1.0
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.