Cannot have ']]>' inside an XML CDATA block.

If you edit Umbraco content and insert JavaScript code, you will end up with the following error: Cannot have ‘]]>’ inside an XML CDATA block.

An easy way to get around this is to add the JavaScript to a Razor scripting file, create a macro that uses the scripting file, and add the macro to the content via the content editor.

As a developer working with Umbraco, if you have a requirement that states your customers need the ability to add their own forms, tweet feeds, facebook like book, etc. via the content editor, make them available to editors via macros. This is by far the safest way for editors to add complex features to editable areas.

Easy Umbraco Forms

I am currently redeveloping the website of the company I work for using Umbraco. There are a number of pages that have different requirements for forms such as a contact form, support form, and contract renewal form. The easiest way to add forms to content pages is to create macros that can be inserted via the editor. This way the content editor has complete control over where they will place the form for maximum effect.

To create a form macro is straight forward enough. Log onto Umbraco and go to the developer section. Create a new Scripting File, and make sure that the Create Macro checkbox is ticked. Once your Razor file has been created, you can then enter the source code and save it. When you are done, select the content tab and click on the file you want to add the form to. Select the Content tab and place your cursor where you want to add the form. Then insert the macro that you have just created and publish your page. That’s all there is to it. The sample source code below is for a simple contract renewal form.

@if (!IsPost)
  <form method="POST">
       <caption>Renew your contract</caption>
         <td>Your Name:</td>
         <td><input type="text" name="name"/></td>
         <td>Your Company:</td>
         <td><input type="text" name="company"/></td>
         <td>The month your contract runs out:</td>
           <select name="expiryMonth">
         <td>Your Email Address:</td>
         <td><input type="text" name="emailAddress"/></td>
         <td>Your Telephone Number:</td>
         <td><input type="text" name="telephoneNumber"/></td>
         <td colspan="2"><input type="submit" name="submit" value="Submit" /></td>
var name = Request["name"];
var company = Request["company"];
var expiryMonth = Request["expiryMonth"];
var emailAddress = Request["emailAddress"];
var telephoneNumber = Request["telephoneNumber"];
var message = "Contract Renewal: Name: " + @name + ", Company: " + @company + ",
 Expiry Month: " + @expiryMonth + ", Email Address: " + @emailAddress + ", Telephone Number: " +
@telephoneNumber;  umbraco.library.SendMail(emailAddress,"",
"Contract Renewal from " + name, message,false);
<p><strong>Thank you for renewing your contract @name</strong>.</p>
<p>Your Genesis Business Systems account manager will be in touch.</p>