Jump to content

Accessing to JavaScript element from TPL in PHP


Theo13

Recommended Posts

Hello,

 

I'm creating a module on Prestashop, and I have a really basic question. I have a TPL file, in which I get a JavaScript object when the users clicks on a button.

 

I want to get this Object in PHP to create a new Prestashop article with the informations of this Object.

But I know it is wrong to call PHP inside of a TPL file.

 

Is my architecture wrong? Is there some option to call my PHP function with this Object as a parameter when I click on my button?

 

Any help would be really appreciated!

Thanks!

Link to comment
Share on other sites

hello

javascripts will not work in php

 

in tpl file you need to create <form> with <input type submit> button

then, in module php controller you will be able to get variables from <form> as a $_POST array (via Tools::getValue('Param') function)

Link to comment
Share on other sites

Okay, I understand how to do that. But how do I call the specific function of my module I want when clicking on the submit button?

in your module file, in your hook function, if the input name is "your_value":

public function hookDisplayYourContent($params) {

  $your_value = Tools::getValue('your_value')
    if(!empty($your_value) {
      //do something....
  }
}

or use ajax in your tpl...

Link to comment
Share on other sites

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...