PerForm Better: How to Process the Sitefinity Forms Responses

PerForm Better: How to Process the Sitefinity Forms Responses

Posted on June 06, 2012 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

Following up on one of the Rado’s posts about implementing notifications for incoming Forms responses, I wanted to cover how to further customize the Forms widget to actually process the individual responses.

Some people would have many specific project requirements. Those include many scenarios and integrations with external systems. In order to achieve those, the developers have to know how to interact with Sitefinity to conForm to the requirements they have. As far as the Sitefinity Forms are concerned there can be many alternative possibilities for integration, but for most of them there is one essential step that needs to be done. This step can be expressed with a simple user case:

As a developer, I would like to be able to process the form responses upon their submission and do whatever I have to do with them…”

Sounds, pretty straightforward, doesn’t it? But before we continue with the ways to do that, lets dive a little deeper into the possible implications of this user case.

What to do with all this inFormation?

The simple widget that I built in this post is aware of the forms responses and you can use it as a base to further process the responses and implement any custom scenario that would involve them.

For instance, you can get any submitted responses and send them to another form to prepopulate its fields or you can even send a specially prepared e-mail that can be imported into a CRM or any other application. This can also come quite handy, if you need to store the responses in another database or just wanted to have a more comprehensive e-mail notification for the Sitefinity admins.

In any way, interacting with the each of the forms responses is very essential and Sitefinity offers an easy way to do so. Now it's showtime!

Let’s Formulate the code then

Probably, this is the most important task that this article has to accomplish. The easiest way to achieve that functionality will be to extend the existing forms widget and provide our additional logic there. So what we really want here is to use the very same Sitefinity forms widget, but with the small difference that when you click the submit button, the code will access the form response and implement any kind of custom logic the business may require.

So in this case, step one will be to create a class that inherits from the default form widget used in Sitefinity. And by inheriting from the main widget class, we will also inherit the designer, the logic, the properties and everything. And here it is:

public class ExtendedForms : Telerik.Sitefinity.Modules.Forms.Web.UI.FormsControl

Step two is to extend the desirable method. In this case, I have chosen to jump into the Submit_Click event handler. So, all I have to do is to override the method then call the base logic and just provide mine afterwards. Simple as that and here is the code:

protected override void Submit_Click(object sender, EventArgs e)
{
base.Submit_Click(sender, e);
// Reads the fields controls on the form
foreach (IFormFieldControl fieldControl in this.FieldControls)
{
// Here you shall put your logic to process the field responses and handle them in a way you would like to
var field = fieldControl as FieldControl;
var value = field.Value;
string title = field.Title;

// In this section, I just create a literal and place it on the main ErrorsPanel of the widget, just to show you that the values are handled properly
Literal theLiteral = new Literal();
theLiteral.Text = String.Format("<p><strong>Value: </strong>{0} >>> <strong>Title: </strong>{1}</p>", value.ToString(), title);
ErrorsPanel.Controls.Add(theLiteral);
ErrorsPanel.Visible = true;
}
}

What is step 3? Sorry, no third step – there are only two. I told you that is going to be easy!

Formal Closing

We are almost done, but there are some important closing details to note about using the code from this blog post.

To use this code, you will have to register the control as Sitefinity widget. The easiest way is to use Sitefinity Thunder with your Visual Studio. If you still don’t have this tool installed in your IDE, please do it because it is really great addition to any ASP.NET development for Sitefinity. In case you would like to install this tool, here are some instructions.

That’s it. Go ahead and download the file of the control. Let us know what you think. I hope that if you have to extend the behavior of the forms module, this resource will help you with the task.

progress-logo

The Progress Team

View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation