Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Build out comment about page form on every page

Vote:
 

We have a "Comment about this page" link on the bottom of every page that opens a form that our constituents use to make comments about whatever pages they are viewing. The form emails our web authors with a page link and the message. I need to reproduce this functionality in EPiServer.

I hope I’m going about this the right way.

I’ve created a block controller called CommentAboutFormController with Name, Email and Message, and am calling this block as a property in SitePageData, since the form needs to be on every page.

 public class CommentAboutForm : BlockData
    {
       
        [Display(Name = "Name")]
        public virtual string name { get; set; }
    
        [Display(Name = "Email")]
        public virtual string email { get; set; }
        
        [Display(Name = "message")]
        public virtual  string message { get; set; }
    }

I created a SubmitComment action result in my default page controller which I'd like  to use to send an email out to our web authors. Right now I’m just debugging to see if I can get form data to pull through.  The form data should be in currentPage.CommentAbout, but it is null

 [HttpPost]
        public virtual ActionResult SubmitComment(SitePageData currentPage)
        {

            var returnURL = UrlResolver.Current.GetUrl(currentPage.ContentLink);

            ...

            return Redirect(returnURL + "#Contact");

        }

This is the form

  @using (Html.BeginForm("SubmitComment", null))
                {
              
                    

                    
* Your Name:

@Html.TextBoxFor(m => m.CurrentPage.CommentAbout.name, new { @class = "form-control", required = "required" }) @Html.ValidationMessageFor(x => x.CurrentPage.CommentAbout.name, "", new { @class = "red" })

* Your Email:

@Html.TextBoxFor(m => m.CurrentPage.CommentAbout.email, new { @class = "form-control", type = "email", required = "required" }) @Html.ValidationMessageFor(x => x.CurrentPage.CommentAbout.email, "", new { @class = "red" })

* Comment:

@Html.TextAreaFor(m => m.CurrentPage.CommentAbout.message, new { @class = "form-control", @cols = 15, @rows = 5, required = "required" }) @Html.ValidationMessageFor(x => x.CurrentPage.CommentAbout.message, "", new { @class = "red" })

}

When I hit submit, I can get the page data to pull through just fine, but the CommentAbout block is always coming though as Null.

Does anyone have any suggestions as to how I can get this form data to pull through? Or perhaps a better way for me to accomplish getting this form on every page?

#195083
Jul 12, 2018 20:40
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.