I recently had a customer request to add a Contact Us form to their DNN installation. It’s something I hadn’t done for a while. In fact, it’s been so long that the language has changed. Last time I played around behind the scenes on DNN (or DotNetNuke as it then was), the language was VB only – this time, the installation is C#. It turned out to be a lot simpler than it was back then, and also gloriously easy to add captcha – another of the customer requirements, as they’re tired of receiving spam from online forms.
I’m guessing that this is something a number of the readers of this blog might need to do some time, so I thought I’d share the easy way to build a DNN form module that includes a captcha.
The first step is to get DNN to create the Module for you. You’re going to do this twice – once on your development machine, and again on the live site.
I ran the development copy of the site from Visual Studio 2012 and logged in as the host. Then I did the following:
You can now close your browser and take a look at the structure DNN has created. We have a new folder structure underneath DesktopModules – an outer Time2yak folder, and a nested ContactUs folder, complete with a Contact.ascx file:
If you open the web user control in the designer, this is what you get:
That’s given us a good starting point – but the first thing we’re going to do is delete the Contact.ascx user control. Just make sure you copy the value of the inherits attribute from the DotNetNuke.Entities.Modules.PortalModuleBase directive at the top of the ascx page before you delete it:
Now we’re going to create our own user control with a separate code behind page.
This is the easiest part of all. Just use the same steps to create the module on the live server that you did in development, and then copy your version of contact.ascx over the version on the live site. You now have the module in place and it appears in the modules list and can be added to any page you want:
And when you add it to the page, you have a Contact Us form with a captcha, developed as a DNN module:
The only other step is to use DNN to create the ThankYou.aspx page that the form passes through to – and that’s just a matter of using the CMS and doesn’t involve any coding.
For other related information, check out these courses from Learning Tree: