Pimping the Kentico forms application

Nov 25, 2016
KenticoCMS

At Ridgeway, we’ve often thought is that there are a few places where the CMS desk could make our lives a little easier. One of the little things - those one percent improvements - is in the forms application. Depending on what you’re doing with your form, you may want to simply display some text to the user once they’ve filled in the form to say “thank you”. The option we get for this is a simple text box, so everything you want to say goes in here.

While I was running through some inductions for a couple of new developers recently we walked through the forms application and this field grabbed my attention. What if I want to do something a little more than say “thanks”, how could this be improved?

Having previously read an article by Laura Frese about enriching the HTML support for notification email templates (Kentico Quick Tip: Full HTML Toolbar for Notification Templates). Effectively, this was a catalyst to the thought that I could more than likely do something to the forms application to improve the editor experience.

What do you get out of the box?

The out-of-the-box feature of Kentico is to give you the option of one of four actions that can happen when you submit a form. The options you get are:

  • Display text: Displays some text that you provide.
  • Redirect to URL: Take me somewhere else - literally anywhere else - as long as it a valid absolute or relative URL.
  • Clear form: Simple clear the form fields and do nothing else.
  • Continue editing: Carry on like nothing happened
bac22c48-bd97-409d-86f3-54de68c48b01

Some options seem a bit odd at first glance, but they do all have their uses depending on the context in which you’re using the form. The two that are most interesting to me are ‘Display text’ and ‘Redirect to URL’. You notice how they’re both text boxes? This could be nicer, using a Rich text editor and URL selector feels like it might be a bit friendlier, right?

Let’s take a look and see if we can easily enable a rich text editor for ‘Display text’.

HTML editor for display text

  • Open ~/CMSModules/BizForms/Tools/BizForm_Edit_General.aspx
  • Change txtDisplay from CMSTextBox to CMSHtmlEditor
  • In code behind add method to initialize the CMSHtmlEditor that is called from the Page_Load
  • Modify references in code behind for txtDisplay.Text to txtDisplay.ResolvedValue
  • If you want, rename txtDisplay to something a little more reflective such as htmlEditor.

Once that is done and you’ve given everything a quick build, you should be able to reload your forms application in CMS desk and be able to set some rich content as shown below:

bfae3277-b7aa-4e3d-935a-c9d1815f23a8

Summary

This is a simple change, but as a content editor and forms administrator, it can give you greater control over what you display once your form is submitted in the cases where you don’t want a separate success page.

Disclaimer: As with many things, we’re changing some OOB features here - so you need to be careful when it’s hot-fix time that you don’t simply lose these changes.