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