Angel Moral Posted April 5, 2019 Share Posted April 5, 2019 I created a prestashop page with php, I use a page controller and the page.tpl, the problem is that I have a button that calls a function of the controller but this does not happen, but the function is called automatically when refresh the page. Link:https://www.710.es/new710/es/nadie Link to comment Share on other sites More sharing options...
Rhobur Posted April 7, 2019 Share Posted April 7, 2019 it is only logical it happens this way, I suggest you remove the call from the tpl page and call your function form JS file using AJAX. Link to comment Share on other sites More sharing options...
Angel Moral Posted April 8, 2019 Author Share Posted April 8, 2019 How can i do that? Link to comment Share on other sites More sharing options...
Rhobur Posted April 8, 2019 Share Posted April 8, 2019 https://www.prestashop.com/forums/topic/960649-pass-data-from-js-to-controller/?do=findComment&comment=3075023 Link to comment Share on other sites More sharing options...
Angel Moral Posted April 8, 2019 Author Share Posted April 8, 2019 I have do this: And show me this error, I have looked in forums and the syntax is correct. Link to comment Share on other sites More sharing options...
Rhobur Posted April 8, 2019 Share Posted April 8, 2019 $this -> context -> controller -> addJS($this -> _path . '/views/js/front.js'); add the JS code into the module's front.js which in turn has to be loaded by the module using the PS built in functions. You need to study the PS or other modules code to understand how it supposed to work. Link to comment Share on other sites More sharing options...
Angel Moral Posted April 9, 2019 Author Share Posted April 9, 2019 i dont know where is module's front.js. I have not create a module, i created a controller in controllers/front/NadieController.php and i would link to call it in nadie.tpl. I resolve the error in syntax. Now my files look like this: nadie.tpl (themes/classic/templates) {extends file='page.tpl'} {block name='page_title'} <span class="sitemap-title">{l s='Plantilla descargable' d='Shop.Theme'}</span> {/block} {block name='page_content_container'} <section> <p><label>Introduce ancho:</label> <input type="text" id="name" name="name" maxlength="8" size="10" /></p> <p><label>Introduce alto:</label> <input type="text" id="name" name="name" maxlength="8" size="10" /></p> <button onclick="myFunction()">Click me</button> <p id="demo"></p> </section> {literal} <script> function myFunction() { document.getElementById("demo"); console.log("Entro myfuncion"); $.ajax( { type: 'POST', data: {action:'getPDF'}, url: here i need to call NadieController, success: function (response) { console.log(response); } } ); } </script> {/literal} {/block} NadieController.php <?php class NadieControllerCore extends FrontController { public $php_self = 'nadie'; public function initContent() { parent::initContent(); if(isset($_POST['action']) && !empty($_POST['action'])) { echo "<script>console.log( 'Entro IF' );</script>"; $action = $_POST['action']; switch($action) { case 'getPDF' : getPDF();break; // ...etc... } } $this->setTemplate('nadie'); } public static function getPDF(){ ob_start(); require('vendor/fpdf/fpdf.php'); $pdf = new FPDF('P','mm',array(20,10)); $pdf->AddPage(); $pdf->Output(); } } 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