prestashopnew Posted April 6, 2016 Share Posted April 6, 2016 Hello everyone, I'm reading this book: https://books.google.it/books?id=BsSiBQAAQBAJ&pg=PT67&lpg#v=onepage&q&f=false I have a problem. The book guides you in creating a module that allows users to add a comment in the product screen. I got to page 32 which explains how to view comments. I can enter and view the written comment, but every time I refresh the page, the comment is duplicated automatically. Any of you know the book or know how to solve this problem? Thanks in advance. This is the displayProductTabContent.tpl file http://dpaste.com/292NYD8 Thank you Link to comment Share on other sites More sharing options...
presta.show Posted April 6, 2016 Share Posted April 6, 2016 Probably when you refresh the page you sends form data again. You should add hidden input in form with key and check the key was used to submit the form before. 1 Link to comment Share on other sites More sharing options...
shokinro Posted April 6, 2016 Share Posted April 6, 2016 as @kalifsoup has mentioned, when you refresh the page, actually the form will be submitted again, usually you see a confirmation popup window from browser about the re-submit the data. here what you can do to avoid this 1. after process the data, redirect to URL to the same page, so even user refresh the page, it will not resubmit the data again, 2. change to use ajax to post data and process in ajax method, only update the page partially instead of post whole page back Link to comment Share on other sites More sharing options...
prestashopnew Posted April 7, 2016 Author Share Posted April 7, 2016 (edited) Thanks for both answers. I do not know very well ajax so I would not know how to do. I know the html but still I can not fix, I tried to rediret to the same page after sending data, but if I refresh the page, the last comment continues to duplicate itself endlessly. I tried to put in action the address, or the onSubmit method, even the hidden input type, but still nothing. Edited April 7, 2016 by prestashopnew (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted April 7, 2016 Share Posted April 7, 2016 You should be able to know it is a post back from a form or not in your php code. You should only process the playback data and then redirect. If it is a redirect back, do not redirect again. Link to comment Share on other sites More sharing options...
prestashopnew Posted April 8, 2016 Author Share Posted April 8, 2016 (edited) Unfortunately I have not an experienced programmer, but I just noticed that it is a general problem. Even when I subscribe to the newsletter and then I update the page without typing anything, the module tells me that I have already registered, because it resends the data. So it's not a problem of my module? This is the php files of my module http://dpaste.com/3DDFJ84 Edited April 8, 2016 by prestashopnew (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted April 8, 2016 Share Posted April 8, 2016 if it is a 3rd party module, then it is better to contact the developer to provide a solution. otherwise you may have to try to figure out by yourself. Link to comment Share on other sites More sharing options...
prestashopnew Posted April 8, 2016 Author Share Posted April 8, 2016 As I said in the first post, I am following this official guide: https://books.google.it/books?id=BsSiBQAAQBAJ&pg=PT67&lpg#v=onepage&q&f=false Unfortunately does not refer to this issue. About the newsletter module, it is the default one, when you install prestashop. 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