Developer forum

Forum » Dynamicweb 10 » Comments Module Implementation Question

Comments Module Implementation Question

Joseph Vause
Reply

Hello,

I just wanted to raise a query with regards to the comment module that dynamicWeb has to allow users to leave ratings and reviews on products. 

I have followed the guide here that goes through a basic implementation: https://doc.dynamicweb.dev/documentation/implementing/ssr/products/comments.html

I am however having issues with this line: <form method="post" action="/Default.aspx?ID=@pageView.ID" id="commentform">

In my implementation i when i post to this form i get a 404 error page

I have tried various ids here and each return the same error, so i am just wondering what this should be set to.

I have implemented this functionality in a new item type and it inherits from the paragraph view model.

@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>

I have set my form to use the @Pageview.ID as per the instructions initially

<form method="post" action="/Default.aspx?ID=@Pageview.ID" id="commentform">

I have then tried to use the Global:Page.Id, product.Id, Model.Id, Model.PageId

all of these return the same 404 error so i am at a bit of a loss as to what is wrong with my implementation. 

This widget is placed on the product detail page and has the current product context added to the widget using this code:

ProductViewModel product = null;
if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
{
    product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
}
else if (Pageview.Page.Item["DummyProduct"] != null && Pageview.IsVisualEditorMode)
{
    var pageViewModel = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page);
    var productList = pageViewModel.Item.GetValue("DummyProduct") != null ? pageViewModel.Item.GetValue("DummyProduct") as ProductListViewModel : new ProductListViewModel();

    if (productList?.Products is not null)
    {
       product = productList.Products[0];
    }
}

The rest of my form is implemented pretty much as is, with the relevant values passed across:

<form method="post" action="/Default.aspx?ID=@Pageview.ID" id="commentform">

    <!--These fields instruct DW10 to create a comment for a product-->
    <input type="hidden" name="Comment.Command" id="Comment.Command" value="create" />
    <input type="hidden" name="Comment.ItemType" value="ecomProduct" />

    <!--This field controls if the comment is active when created. Set to false if you want to approve comments before publishing them-->
    <input type="hidden" name="Comment.Active" value="true" />

    <!-- These values make sure the comment is registered to the right product -->
    <input type="hidden" name="Comment.ItemID" value="@product.Id" />
    <input type="hidden" name="Comment.LangID" value="@product.LanguageId" />

    <!--Comment.Continue takes an URL to redirect the user to after submitting their comment. Defaults to -->
    <input type="hidden" name="Comment.Continue" value="/shop?ProductId=@product.Id" />

    <!--Comment.ParentID should be set to the ID of the comment which is being replied to - here this is done via the comment_reply JS function-->
    <input type="hidden" name="Comment.ParentID" id="Comment.ParentID" value="0" />

    <!--Notification email details - intended to notify someone to review this comment-->
    <input type="hidden" name="Comment.Notify" value="false" />
    <input type="hidden" name="Comment.NotifyTemplate" value="Comments/Notify.cshtml" />
    <input type="hidden" name="Comment.NotifySubject" id="Comment.NotifySubject" value="New comment on @product.Name " />
    <input type="hidden" name="Comment.NotifySenderEmail" value="noreply@dynamicweb.dk" />
    <input type="hidden" name="Comment.NotifySenderName" value="Website comment" />
    <input type="hidden" name="Comment.NotifyEmail" value="cbo@dynamicweb.dk" />

    <!--Notification email settings for replies-->
    <input type="hidden" name="Comment.Reply.Notify" value="false" />
    <input type="hidden" name="Comment.Reply.NotifyTemplate" value="Comments/ReplyNotify.cshtml" />
    <input type="hidden" name="Comment.Reply.NotifySubject" value="SomeValue" />
    <input type="hidden" name="Comment.Reply.NotifySenderEmail" value="noreply@dynamicweb.dk" />
    <input type="hidden" name="Comment.Reply.NotifySenderName" value="Webmaster" />

    <!-- Comment Input Fields - your users will typically add data to these-->
    <div class="row">
       <div class="col-12 col-md-6">
          <label for="Comment.Name" class="text-label-red">Name</label>
          <input type="text" class="form-control text-input-field" name="Comment.Name"  id="Comment.Name" value="@UserContext.Current.User.Name" /><br />

       </div>
       <div class="col-12 col-md-6">
          <label for="Comment.Email" class="text-label-red">E-mail </label>
          <input type="text" class="form-control text-input-field" name="Comment.Email" id="Comment.Email" value="@UserContext.Current.User.Email" /><br />
       </div>
    </div>

    <div class="row">
       <div class="col-12 col-md-6">
          <label for="Comment.Website" class="text-label-red">Company</label>
          <input type="text" class="form-control text-input-field" name="Comment.Website" id="Comment.Website" value="@UserContext.Current.User.Company" /><br />

       </div>
       <div class="col-12 col-md-6">
          <label for="Comment.Email" class="text-label-red">Your rating</label>
          <select name="Comment.Rating" id="Comment.Rating"></select>
       </div>
    </div>
    <div class="row">
       <div class="col-12">
          <label for="Comment.Text" class="text-label-red">Comments</label>
          <textarea class="form-control text-input-field" name="Comment.Text" id="Comment.Text" rows="10" cols="50"></textarea><br />
       </div>
    </div>
    
    <input class="btn btn-primary" type="submit" value="@Translate("Submit Review")" />

</form>

The Ratings Drop down has been implemented using choices.js to allow the styling we want, hence why there are no options within it

There are also two lines in here that i am also not sure about:

<!--Comment.Continue takes an URL to redirect the user to after submitting their comment. Defaults to -->
<input type="hidden" name="Comment.Continue" value="/shop?ProductId=@product.Id" />

<!--Comment.ParentID should be set to the ID of the comment which is being replied to - here this is done via the comment_reply JS function-->
<input type="hidden" name="Comment.ParentID" id="Comment.ParentID" value="0" />

I want the user to just be returned to the page they are on currently and i do not want to implement replies at this time. Just single level comments.

For additional context, we are using the URL provider to route the correct information to the product detail page so that it displays whatever product was selected from the product grid/list page

 

So my questions are:

- What do i need to set the forms action to in this scenario, i thought it was just the current page

- What do i need to set the comment.continue value to if i do not want to take the user to a different page when submitting, but instead just return them to the same page they were on

- If i omit the Comment.ParentId, or set it as 0 like it is now, will that always be a top level comment, or does it need to be set to something else, like the product Id.

 

Any help would be greatly appreciated on this as i am a little stuck. 

Kind regards,

Joe CV

 


Replies

 
Justin Sjouw Dynamicweb Employee
Justin Sjouw
Reply

Hi Joe,

Unfortunately I don't have time to read your full issue in detail right now, but I have a working template (a bit hacky maybe) for comments, maybe that helps you find the issue?

I attached the cshtml here...

Cheers,

Justin

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Joe,

The 404 probably occurs because the system detects some form of malicious/suspicious data in the comment post.
We perform some spam checks when the comment form is posted and respond with a 404 if we find anything.
Try to take a look at the event log in DynamicWeb and see if there are any warnings in the security category. The event description should contain some additional info about why the post was considered as spam.

Otherwise, it could also happen if the url you have provided in "Comment.Continue" is invalid. You can try to remove that part and see if it works.

/Morten

 
Joseph Vause
Reply

Thanks both for your rapid responses.

@Justin Thanks for clearing up what the URL should be, that makes more sense as it captures the route by the URL provider.

@Morten, you were right about the spam. Returning a 404 feels a little suspect though, as i would expect it to be a 403 as 404 implies that the URL is incorrect, not that the request was forbidden (due to spam)

I have pulled the error from the logs, 

Banned ip: ::1; REASON: Form BAN: Bad form (SessionID has changed between form rendering and submit - FormCH1_s); Bad form (Session field FormCH1_h not updated by script); Bad form (IP has changed from form rendering until submit - FormCH1_i); Bad form (missing timestamp field - ts); Bad form (Hidden email field (email) altered to );

Im not sure how best to handler this. The hidden email field altered to "" is odd as i am posting with what is put into the form on page load (@UserContext.Current.User.Email)

developing locally, how can i enable ::1 to be able to test this locally, as ::1 should not be banned until we want it to be, such as in production.
 

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

You probably need to disable the built in spam detection for comments. As far as I remember the comment spam detection only works if you implement the comment form in a product template for the older product catalog module that doesn't use view models.

  1. Go to Settings > System > Web & http > Security
  2. Disable (uncheck) the setting "Activate antispam functionality for comments"

 

You must be logged in to post in the forum