I would like to add a review form in my custom module front end page. On this page, I have displayed several selected products.
I want to display a review form in front of each product each review form on my custom page.
Please see the below attached screenshot for better understand.
How can I achieve these things? Make sure each product have a separate review form and it should be default Magento review form.
<div> <?php echo $block->getLayout()->createBlock("Magento\Review\Block\Form")->setTemplate('Namespace_ModuleName::form.phtml')->toHtml(); ?> </div>
Using create a block and set template method I am able to display review form. but I am getting trouble in submitting the form. because In my custom review page form action parameter is not passing the product ID.
The current review form action is like
What actually review form action (It should be like below).
Why ID is not passing in the form action. Is it a wrong method to display review form? or is there any other way to display review form?
After creating a custom block and extend my block to
\Magento\Review\Block\Form(default) then I am able to see product ID in form action URL.
<div> <?php echo $block->getLayout()->createBlock("Namespace\ModuleName\Block\ReviewForm")->setTemplate('Namespace_ModuleName::form.phtml')->toHtml(); ?> </div>
Now I can see separate review form for a separate product. But in console, I am getting an error like below.
Uncaught SyntaxError: Unexpected token u in JSON at position 0
Because of the above error, I am not able to submit a review for all product. can anyone help me to solve out this problem?
Any help would be appreciated!