public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            UserFeedbackDb       db       = new UserFeedbackDb();
            UserFeedbackFormInfo formInfo = db.getUserFeedbackFormInfo(page, identifier, langToRenderFor, true);
            string ControlId = "UserFeedbackInfo_" + page.ID.ToString() + "_" + identifier.ToString() + "_" + langToRenderFor.shortCode + "_";

            string action = PageUtils.getFromForm(ControlId + "Action", "");

            if (action.Trim().ToLower() == "update")
            {
                formInfo.EmailAddressesToNotify = PageUtils.getFromForm(ControlId + "EmailAddressesToNotify", formInfo.EmailAddressesToNotify);
                formInfo.ThankyouMessage        = PageUtils.getFromForm(ControlId + "ThankyouMessage", formInfo.ThankyouMessage);
                formInfo.TextAreaQuestion       = PageUtils.getFromForm(ControlId + "TextAreaQuestion", formInfo.TextAreaQuestion);
                db.saveUpdatedUserFeedbackFormInfo(page, identifier, langToRenderFor, formInfo);
            }

            StringBuilder html = new StringBuilder();

            html.Append("<table>");
            html.Append("<tr>");
            html.Append("<td valign=\"top\">");
            html.Append("Email addresses to notify of form submissions: ");
            html.Append("</td>");
            html.Append("<td valign=\"top\">");
            html.Append(PageUtils.getInputTextHtml(ControlId + "EmailAddressesToNotify", ControlId + "EmailAddressesToNotify", formInfo.EmailAddressesToNotify, 50, 255));
            html.Append("<br>");
            html.Append("<font size=\"1\">(seperate addresses with semi-colons (;)</font>");
            html.Append("</td>");
            html.Append("</tr>");

            html.Append("<tr>");
            html.Append("<td valign=\"top\">");
            html.Append("Text area question text: ");
            html.Append("</td>");
            html.Append("<td valign=\"top\">");
            html.Append(PageUtils.getInputTextHtml(ControlId + "TextAreaQuestion", ControlId + "TextAreaQuestion", formInfo.TextAreaQuestion, 50, 255));
            html.Append("</td>");
            html.Append("</tr>");

            html.Append("<tr>");
            html.Append("<td valign=\"top\">HTML message to display to user upon successful submission:");
            html.Append("</td>");
            html.Append("<td valign=\"top\">");
            html.Append(PageUtils.getTextAreaHtml(ControlId + "ThankyouMessage", ControlId + "ThankyouMessage", formInfo.ThankyouMessage, 30, 5));
            html.Append("</td>");
            html.Append("</tr>");
            html.Append("</table>");

            html.Append(PageUtils.getHiddenInputHtml(ControlId + "Action", "update"));


            writer.Write(html.ToString());
        } // RenderEdit
        public override void RenderInViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            UserFeedbackDb       db       = new UserFeedbackDb();
            UserFeedbackFormInfo formInfo = db.getUserFeedbackFormInfo(page, identifier, langToRenderFor, true);
            string ControlId = "UserFeedbackInfo_" + page.ID.ToString() + "_" + identifier.ToString() + "_" + langToRenderFor.shortCode + "_";

            string _errorMessage = "";
            string action        = PageUtils.getFromForm(ControlId + "Action", "");
            UserFeedbackSubmittedData submittedData = new UserFeedbackSubmittedData();
            bool formValuesLoadedFromSession        = false;

            if (action.Trim().ToLower() == "send")
            {
                // -- get the spam question index
                int spamQuestionIndex = (PageUtils.getFromForm(ControlId + "spamQuestionIndex", SpamTestQuestion.GetRandomQuestionIndex()));
                if (spamQuestionIndex >= SpamTestQuestion.Questions.Length || spamQuestionIndex < 0)
                {
                    spamQuestionIndex = SpamTestQuestion.GetRandomQuestionIndex();
                }

                SpamTestQuestion questionToAnswer = SpamTestQuestion.Questions[spamQuestionIndex];

                string spamQuestionAnswer = (PageUtils.getFromForm(ControlId + "spamQuestionAnswer", ""));

                submittedData.Name          = (PageUtils.getFromForm(ControlId + "Name", ""));
                submittedData.Name          = submittedData.Name.Trim();
                submittedData.EmailAddress  = PageUtils.getFromForm(ControlId + "Email", "");
                submittedData.EmailAddress  = submittedData.EmailAddress.Trim();
                submittedData.Location      = PageUtils.getFromForm(ControlId + "Location", "");
                submittedData.Location      = submittedData.Location.Trim();
                submittedData.TextAreaValue = PageUtils.getFromForm(ControlId + "Comments", "");
                submittedData.TextAreaValue = submittedData.TextAreaValue.Trim();
                submittedData.ReferringUrl  = PageUtils.getFromForm(ControlId + "Referer", "");

                // -- validate user submitted values
                if (questionToAnswer.Answer != spamQuestionAnswer)
                {
                    _errorMessage = "Your answer to the math question was incorrect. Please try again.";
                }
                else if (submittedData.Name == "")
                {
                    _errorMessage = getErrorEnterNameText(langToRenderFor);
                }
                else if (submittedData.EmailAddress == "")
                {
                    _errorMessage = getErrorEnterEmailText(langToRenderFor);
                }
                else if (!PageUtils.isValidEmailAddress(submittedData.EmailAddress))
                {
                    _errorMessage = getErrorEnterValidEmailText(langToRenderFor);
                }
                else if (submittedData.TextAreaValue == "")
                {
                    _errorMessage = getErrorEnterTextAreaQuestionText(langToRenderFor) + formInfo.TextAreaQuestion;
                }
                else
                {
                    // -- save the submitted value
                    submittedData.dateTimeSubmitted = DateTime.Now;
                    submittedData.TextAreaQuestion  = formInfo.TextAreaQuestion;

                    if (db.saveUserFeedbackSubmittedData(submittedData))
                    {
                        // -- success
                        //    save submitted values to the current session
                        if (HttpContext.Current != null && HttpContext.Current.Session != null)
                        {
                            System.Web.SessionState.HttpSessionState session = System.Web.HttpContext.Current.Session;
                            session[ControlId + "Name"]     = submittedData.Name;
                            session[ControlId + "Email"]    = submittedData.EmailAddress;
                            session[ControlId + "Location"] = submittedData.Location;
                        }
                        //    send notification email message
                        sendAdministratorNotification(formInfo, submittedData);
                        //   output the Thankyou message
                        writer.Write("<p><strong>" + formInfo.ThankyouMessage + "</strong></p>");
                        return;
                    }
                    else
                    {
                        _errorMessage = getErrorSavingText(langToRenderFor);
                    }
                }
            } // if save posted values
            else
            {
                // -- get previously submitted values from the current session
                if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Session != null)
                {
                    System.Web.SessionState.HttpSessionState session = System.Web.HttpContext.Current.Session;
                    if (session[ControlId + "Name"] != null)
                    {
                        submittedData.Name          = session[ControlId + "Name"].ToString();
                        formValuesLoadedFromSession = true;
                    }
                    if (session[ControlId + "Email"] != null)
                    {
                        submittedData.EmailAddress  = session[ControlId + "Email"].ToString();
                        formValuesLoadedFromSession = true;
                    }
                    if (session[ControlId + "Location"] != null)
                    {
                        submittedData.Location      = session[ControlId + "Location"].ToString();
                        formValuesLoadedFromSession = true;
                    }
                }
            }


            StringBuilder html = new StringBuilder();

            if (_errorMessage != "")
            {
                html.Append("<p class=\"FormErrorMessage\">" + _errorMessage + "</p>");
            }

            string formId = "UserFeedback";

            html.Append(page.getFormStartHtml(formId));

            html.Append("<em>" + getCompleteAllText(langToRenderFor) + "</em> ");
            if (formValuesLoadedFromSession)
            {
                html.Append(getValuesPreloadedText(langToRenderFor));
            }

            html.Append("<table>");
            html.Append("<tr>");
            html.Append("<td valign=\"top\">" + getNameText(langToRenderFor) + ":");
            html.Append("</td>");
            html.Append("<td valign=\"top\">");
            html.Append(PageUtils.getInputTextHtml(ControlId + "Name", ControlId + "Name", submittedData.Name, formInfo.FormFieldDisplayWidth, 255));
            html.Append("</td>");
            html.Append("</tr>");

            html.Append("<tr>");
            html.Append("<td valign=\"top\">" + getEmailText(langToRenderFor) + ":");
            html.Append("</td>");
            html.Append("<td valign=\"top\">");
            html.Append(PageUtils.getInputTextHtml(ControlId + "Email", ControlId + "Email", submittedData.EmailAddress, formInfo.FormFieldDisplayWidth, 255));
            html.Append("</td>");
            html.Append("</tr>");

            html.Append("<tr>");
            html.Append("<td valign=\"top\">" + getLocationText(langToRenderFor) + ":");
            html.Append("</td>");
            html.Append("<td valign=\"top\">");
            html.Append(PageUtils.getInputTextHtml(ControlId + "Location", ControlId + "Location", submittedData.Location, formInfo.FormFieldDisplayWidth, 255));
            html.Append("</td>");
            html.Append("</tr>");

            html.Append("<tr>");
            html.Append("<td valign=\"top\">");
            html.Append(formInfo.TextAreaQuestion);
            html.Append("</td>");
            html.Append("<td valign=\"top\">");
            html.Append(PageUtils.getTextAreaHtml(ControlId + "Comments", ControlId + "Comments", "", formInfo.FormFieldDisplayWidth, 7));
            html.Append("</td>");
            html.Append("</tr>");

            // -- spam stop question
            int qIndex = SpamTestQuestion.GetRandomQuestionIndex();
            SpamTestQuestion spamQuestion = SpamTestQuestion.Questions[qIndex];

            html.Append("<tr>");
            html.Append("<td valign=\"top\">");
            html.Append(spamQuestion.Question);
            html.Append("</td>");
            html.Append("<td valign=\"top\">");
            html.Append(PageUtils.getInputTextHtml(ControlId + "spamQuestionAnswer", ControlId + "spamQuestionAnswer", "", 5, 255));
            html.Append("</td>");
            html.Append("</tr>");

            html.Append("</table>");

            html.Append(PageUtils.getHiddenInputHtml(ControlId + "spamQuestionIndex", qIndex.ToString()));
            html.Append(PageUtils.getHiddenInputHtml(ControlId + "Action", "send"));
            html.Append(PageUtils.getHiddenInputHtml(ControlId + "Referer", PageUtils.getFromForm("r", "(unknown)")));

            html.Append("<input type=\"submit\" value=\"" + getSubmitButtonText(langToRenderFor) + "\">");
            html.Append(page.getFormCloseHtml(formId));

            writer.Write(html.ToString());
        } // RenderView