Using XForms to store information

At the moment I’m adding some functionallity to vinsprit.se, so that a visitor can add products, that aren’t in the regular assortment, to a cart and by a simple click send this cart by fax to the closest Systembolag. A pretty nice feature. The customer also wanted to store the orderinfo in episerver if something goes wrong, so I thought that you must be able to do that with XForms. And yes, it was very simple.

First of all I added a “XForms form”-property to the pagetype. Then I made an empty Form. The rest is handled from code behind. The following example works both with 4.6 and CMS 5. Hopefully in CMS 5 R2 aswell.. 🙂

// Get guid for the form and creates instance
XForm form = XForm.CreateInstance(new Guid((String)CurrentPage["XFormPropertyName"]));
// This is where data is stored
XFormData form_data = form.CreateFormData();
//We want this info related to the order page
form_data.PageId = CurrentPage.PageLink.ID;
// We want it saved in the database
form_data.ChannelOptions = ChannelOptions.Database;

// Here we add the values.
form_data.SetValue("Key 1", "some value");
form_data.SetValue("Key 2", "some other value");
// and saves it
form_data.Send();

Pretty nice if you want to avoid creating your own sql-table or some other way to store data.

932 thoughts on “Using XForms to store information

  1. Michel

    Hi,
    I need fax functionality for a site I’m working on. How did you do it? Did you use a third party component/service?

  2. Per N

    This looks very intresting. I guess that it should work to gather information
    in a scheduled job and store the information on any page with a xform as long as you somehow now which page to use?

  3. David Einebrant

    Nice article!

    As I understand, the data from the form is saved in the table tblItem. But when use the sql profiler, I cant see the data in clear text. It looks like its encrypted.

    Is it possible to use the form data information stored in the database directly, using another system, for example Reporting Services?

  4. jakub

    I try to find external component similar to “Episerver xFrom” but a little more complex.
    Through complex I understand possibility to create more advance (more controls…) and more flexible self-styling Forms (without extra styling work).

    Is anyone who run into this kind of components ? I want to make use of this as a substitute for xForm in my Episerver project.

Comments are closed.