Wednesday, February 24, 2010

Web entry forms on SharePoint Proof Of Concept

On almost each publishing website some kind of contact form is present. When developing a site with SharePoint one can create forms with:
* Infopath
* Third party provider (for example Kodision)
* A form generator based on a SharePoint List (for example SFG)

Each solution has it's own pro's and con's. Most of the time a solution like SFG suffices and has the advantage that the forms can be maintained by ContentEditors themselves. SFG generates form fields based on the columns of a specific list. Upon submitting the form by a visitor, a new listitem will be added to the list with the values enterd by the visitor.

Unfortunatly when Content Deployment is put in the mix to achieve a seperate content authoring farm and a production farm situation, the form data will be stored on the production farm. Most of the time this farm will not be accessible by ContentEditors (anonymous access only) and thus the form data is inaccessible. It's ofcourse possible to extend the WebApplication, but this probably causes confusion for the ContentEditors and is prone to editting on the wrong farm.

By nature "Form Generators" are not very suitable for implementing exceptions.

As a Proof Of Concept i've written a very simple solution called "UserControlFormSolution" which consists of a simple form processing back-end. The front-end must be a UserControl (ascx) which inherits from the back-end class. On the front-end one can place regular CustomControls (textboxes, checkboxes, uploadcontrols, validationcontrols).

The back-end does a simple transfer of the Input-controls (from the UserControl) to the fields of a specified list by matching their names. So to fill the Title-field of a listiem, the UserControl may contain:



Instead of using the ObjectModel to store the listitem, i chose to use the Lists WebService and thus enable storing data in a remote farm.

The source code is placed on CodePlex here.

But the story does not end here as a UserControl needs to be placed on a page. This would mean that for each form one must create a specific PageLayout and add the UserControl to the main placeholder. To overcome this requirement i´ve used the UserControlHostingWebPartSolution. This solution provides a SmartPart-like webpart with which one can host a UserControl. This solution provides the extra functionality to be able to set properties of the UserControl.



To enable ContentEditors to maintain the form UserControls, the ASCX-files must be made accessible. To achieve this i've used the SharePointHostedUserControlsSolution. This solution enables one to host UserControls from within a document library (/UserControls/) from the SharePoint SiteCollection. The Solution contains a WebApplication Feature to modify the web.config.

At this point your ContentEditors can use SharePoint Designer to modify a form.