pippo67 Posted February 14, 2018 Share Posted February 14, 2018 Hello, I've created a custom form with star ratings. I am using ajax to send the form, but ajax not working. I do not receive errors and the status is OK: 200.Where am I doing wrong? This is the structure of the tpl file <div class="starrr" id="rating-comment"></div> <div id="commentFormBody"> <textarea id="comment" rows="10" cols="50"></textarea> </div> </div> <div id="commentSubmitButton"> <input type="submit" id="submit" value="submit" /> </div> </div> <!-------- STAR RATING --------> <script type="text/javascript"> {literal} var rating; $('#rating-comment').starrr({ change: function(e, value){ rating = value; if (value) { $(".your-choice-was").show(); $(".choice").text(value); } else { $(".your-choice-was").hide(); } } }); <!-------- AJAX SUBMIT ------> $('#submit').click(function() { var comment = $('#comment').val(); var baseDIR = 'http://localhost:8080/shop/' $.ajax({ url: baseDIR + 'modules/mymodule/controllers/front/save.php', type: 'POST', data: { comment: comment, rating: rating, ajax: true, }, success: function(status) { .................................... }); }); This is the php file <?php if (!defined('_PS_VERSION_')) exit; class MymoduleSaveModuleFrontController extends ModuleFrontController { public function initContent() { parent::initContent(); $rating = (int)Tools::getValue('rating'); $comment = trim(Tools::getValue('comment')); if(!empty($comment)) { Db::getInstance()->insert('comments', array( 'rating' => $rating, 'comment' => $comment, )); } $this->setTemplate('save.tpl'); } } Thank you, I'm sorry if I'm presenting the problem here Link to comment Share on other sites More sharing options...
pippo67 Posted March 2, 2018 Author Share Posted March 2, 2018 thanks for the answers, but despite several tests, also referring to the link you told me, the problem remained. So I solved it by changing the structure. One question: in addition to using {literal} {/ literal}, is there another way to insert a js file in the tpl file to keep it separated? I tried using: <script type = "text / javascript"> <src = ",,,,,,,"> </ script> but nothing happens. Link to comment Share on other sites More sharing options...
jgamio Posted March 6, 2018 Share Posted March 6, 2018 your form is load from a custom module ? Link to comment Share on other sites More sharing options...
pippo67 Posted March 16, 2018 Author Share Posted March 16, 2018 yes, it's a custom form. 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