Jump to content

[SOLVED] How to get data from inputs of custom tab in product edit page [1.6.1.x]


Recommended Posts

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!

 

 

tab.png

Link to comment
Share on other sites

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

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.

 

  • Like 1
Link to comment
Share on other sites

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 by onelineof.me
typo (see edit history)
Link to comment
Share on other sites

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

  • razaro changed the title to [SOLVED] How to get data from inputs of custom tab in product edit page [1.6.1.x]

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...