pippo67 Posted February 8, 2018 Share Posted February 8, 2018 Hello,I created a personal comment form with star ratings. I'm using ajax to send the form, the comment is inserted in the db, but the value of the evaluation is 0. The problem I believe is in the Tools: getValue ('rating') method: it does not receive the value of the evaluation. This is code: <div class="starrr" id="rating-comment"/></div> <form action=''> <input type="submit" id="submit" value="" /> <textarea id="comment" rows="10" cols="50"></textarea> </form> <script type="text/javascript"> {literal} var rating; $('#rating-comment').starrr({ change: function(e, value){ rating = value; ................................................... }); $('#submit').click(function() { var comment = $('#comment').val(); $.ajax({ url: baseDIR + 'modules/mymodule/controllers/front/save.php', type: 'POST', data: {comment: comment, rating: rating}, ................... ........ }); }); {/literal} </script> All this is in a tpl file class MymoduleSaveModuleFrontController extends ModuleFrontController { public function initContent() { parent::initContent(); $rating = (int)Tools::getValue('rating'); $comment = trim(Tools::getValue('comment')); thank you. Link to comment Share on other sites More sharing options...
Rhobur Posted February 10, 2018 Share Posted February 10, 2018 try sending the my_module_url variable to js from within your template (using jsDef and link->getModule...) then in your ajax call use url: my_module_url Link to comment Share on other sites More sharing options...
pippo67 Posted February 13, 2018 Author Share Posted February 13, 2018 Thank you for answering me, but I can not understand how I should do it. Could you give me, if possible, an example? Link to comment Share on other sites More sharing options...
Rhobur Posted February 17, 2018 Share Posted February 17, 2018 You can try this, https://www.prestashop.com/forums/topic/589686-prestashop-16-controller-ajax-call/ Apart the fact that the example includes js in tpl (which I advise against), you can look upon {$link->$this->context->getModuleLink('modulename', 'default')} include it in your tpl then add the ajax in the module's js. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now