Use Xform to store data when you have a form with a fixed design
Many of you have probably used xform before and also hate the fact that when the editor create a form inside EPiServer you can not set the layout and design as you like. But xform can be ok to use when store information/data when you have a form that have a specific design and layout or when the editor are not allowed to choose the fields to use.
Since almost every blogpost is about CMS 7 and MVC at the moment I thought this post might help someone still working with CMS 6 or doing ordinary good old EPiServer development
Lately I have been working with a customer that needed a contact form looking something like this:
They hade some requirements for validation and my part in the project was to create the functionality and store the information. The html/css-part was already made by another developer therefore I could note create css and html to fit the ordinary tags that EPiServer Xform will create when you use it as an editor to produce forms.
But since EPiServer allow use to store information in Xform with the API we can create a form locking exactly like this and with the built-in functionality in EPiServer let the editor collect data. This is very simple.
- Create a property of type Xform on the specific PageType
- Create an empty form and set the property to use that form
The rest is done by code. First we need to create our form in html. With the help of web controls we can also use some validation. If you do not like to use validation you can delete the web controls handling validation.
The rest is code behind and it is really simple:
Really nice and easy when you like to store information within a form. Of course you could have use DDS or something like that but since the xform functionality will give the editor control and the capability to export data from the form I think this is ok to use.
In EPiServer CMS 6 the data storage of Xforms and Xform postings is moved to DDS so you could extend your code with searching in forms for instance. You can read more about xforms and dynamic data store in this blogpost by Linus Ekström: http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2010/7/Using-the-dynamic-data-store-with-XForms/