onelineof.me Posted March 5, 2020 Share Posted March 5, 2020 Hello everybody, I'm new here, but this forum has helped me a lot the past days. Now I have my question. I am making a module and I have added a new tab with hookDisplayAdminProductsExtra to product edit page with a form and buttons.(see image) The .tpl that shows the form is: <div class="form-group"> <form> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname" value="John"><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname" value="Doe"> </form> <div> <button class="button btn btn-default" id="cancelConfiguratorProduct" name="cancelConfiguratorProduct" type="submit"><i class="process-icon-save"></i> {l s='Cancel' mod='configurator'}</button> <button class="button btn btn-default pull-right" id="submitConfiguratorProduct" name="submitAddproduct" type="submit"><i class="process-icon-save"></i> {l s='Save' mod='configurator'}</button> </ div> </div> My question is how to get the data from the inputs and store them in variables for later user.(i wiil insert them in database, no problem here.) I have tried experimenting with hookActionProductUpdate but no luck. It seems that it never fires, but even then I don't know how to get the inputs value. I don't know if my logic is correct as I'm new to prestashop, so any help would bee much appreciated! Link to comment Share on other sites More sharing options...
razaro Posted March 6, 2020 Share Posted March 6, 2020 HI welcome to the forum and also welcome do module development. Can be tricky at times. You should be using hookActionProductUpdate function for sure but think you may need to change buttons code. Try with <div class="panel-footer"> <a href="{$link->getAdminLink('AdminProducts')|escape:'html':'UTF-8'}" class="btn btn-default"><i class="process-icon-cancel"></i> {l s='Cancel'}</a> <button type="submit" name="submitAddproduct" class="btn btn-default pull-right"><i class="process-icon-save"></i> {l s='Save'}</button> <button type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> {l s='Save and stay'} </button> </div> That should trigger it. Link to comment Share on other sites More sharing options...
onelineof.me Posted March 6, 2020 Author Share Posted March 6, 2020 Thank you very much for your answer. The problem is I still can't understand how to get the input data in the hookActionProductUpdate. What is the way to store them in a variable there? Sorry for the noob question.. Link to comment Share on other sites More sharing options...
razaro Posted March 6, 2020 Share Posted March 6, 2020 For getting input data you can use Tools::getValue() function public function hookActionProductUpdate($params) { $fname = (int)Tools::getValue('fname'); $lname = (int)Tools::getValue('lname'); // and rest of the code, you can use var_dump($fname); and die(); to check values } Bit older tutorial on topic but might help https://belvg.com/blog/how-to-create-a-custom-product-tab-in-prestashop.html Good luck with development. 1 Link to comment Share on other sites More sharing options...
onelineof.me Posted March 6, 2020 Author Share Posted March 6, 2020 (edited) Thank you again! One last thing. I was using hookActionProductUpdate before too, but it didn't seem to work. I have even tried loging something in a txt file but nothing. I have it on my install function like this among others ..... !$this->registerHook('actionProductUpdate') || .... Am I doing something wrong? Thank you for your answers! Edited March 6, 2020 by onelineof.me typo (see edit history) Link to comment Share on other sites More sharing options...
razaro Posted March 6, 2020 Share Posted March 6, 2020 yes you should have it in install with registerHook but now i see you had correct submit button, so not sure why it did not triggered. Do check in positions, and "display hidden hooks" is it module actual hooked correctly. Link to comment Share on other sites More sharing options...
onelineof.me Posted March 6, 2020 Author Share Posted March 6, 2020 Thank you!! You are a savior! I had it in position hookDisplayFooterProduct because thats what i wanted to do. I transplanted the module to actionProductUpdate and I am able to get the data! I can't thank you enough! 1 Link to comment Share on other sites More sharing options...
razaro Posted March 6, 2020 Share Posted March 6, 2020 Great to hear you found issue and sort it. 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