cyberdoc Posted July 3, 2014 Share Posted July 3, 2014 (edited) hi, this may sound dumb but im sorry for the confusion. i basically have a module for whose frontend ive written a module.tpl now it has a button on clicking which i want to run a function in the module.php.. i'm all confused in these files write now!! shall i go via a js function for onclick?? <Form name ="form1" Method ="Post" ACTION ="function()"> <b><label for="Installation">Installation to be done?</label> <Input type = 'Radio' Name ="install" id ="radio1" onclick = "MyAlert()">DO Installation <Input type = 'Radio' Name ="install" id="radio2" onclick = "MyAlert()">no <button type="submit" VALUE="Update Cart"> </b> </Form> Edited July 4, 2014 by vekia (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted July 3, 2014 Share Posted July 3, 2014 im confused topic title says that you want to run php function from js, in topic contents you said that you want to run php from .tpl file so... ? Link to comment Share on other sites More sharing options...
cyberdoc Posted July 3, 2014 Author Share Posted July 3, 2014 so am i, so finally decided to skip the JS part.. im ok with directly calling back the function only Link to comment Share on other sites More sharing options...
bellini13 Posted July 3, 2014 Share Posted July 3, 2014 i think you are confusing the difference between "form posting" and "function invocation". You have an HTML form that you are submitting, so you would just make the form action URL a php file provided with your module. If using PS 1.5+, this php file would be a module controller that handles the form submission Link to comment Share on other sites More sharing options...
cyberdoc Posted July 3, 2014 Author Share Posted July 3, 2014 yes exactly , so here is what i do.. <Form name ="form1" Method ="Post" ACTION ="update.php"> <b><label for="Installation">Installation to be done?</label> <Input type = 'Radio' Name ="install" id ="radio1" onclick = "MyAler()">DO Installation <Input type = 'Radio' Name ="install" id="radio2" onclick = "MyAler()">no <Input type= 'submit' value="Update Cart" name="submit"> </b> </Form> in the update.php file(in same folder) <? php code.. ?> but it searches for it in the root folder.. what next? also if i go this way it will get the user back after executing the function na?? Link to comment Share on other sites More sharing options...
cyberdoc Posted July 3, 2014 Author Share Posted July 3, 2014 any help guys i know its lame but cant help.. Link to comment Share on other sites More sharing options...
vekia Posted July 3, 2014 Share Posted July 3, 2014 <Form name ="form1" Method ="Post" ACTION ="update.php">instead of it use: <Form name ="form1" Method ="Post" ACTION ="{$content_dir}/modules/YOURMODULE/update.php"> but im affraid that your customer will be redirected to the update.php file and this is not what you're looking for why you use update.php file? why not to use function inside the module class? (main module .php file) Link to comment Share on other sites More sharing options...
cyberdoc Posted July 3, 2014 Author Share Posted July 3, 2014 yes exactly, it'll redirect this way... i'm also thinking the same now.. was having this on a separate .tpl file.. but now thinking of merging with the main module.. Link to comment Share on other sites More sharing options...
cyberdoc Posted July 3, 2014 Author Share Posted July 3, 2014 hey tried that but that puts my form on the top of the page.. when i used the tpl it was coming right.. Link to comment Share on other sites More sharing options...
cyberdoc Posted July 3, 2014 Author Share Posted July 3, 2014 (edited) public function hookdisplayshoppingcartfooter($params) { $cookie = $this->context->cookie; $sub_total=0; $products = $params['cart']->getProducts(true); // print_r($products); // print_r($cookie); foreach ($products as $product) { $result = Db::getInstance()->getRow('SELECT textarea FROM `'._DB_PREFIX_.'belvg_samplemodule` sample WHERE sample.`id_product` = '.$product['id_product']); // print_r($product['id_product']); $sub_total = $sub_total + $result['textarea']; } $result =DB::getInstance()->Execute('UPDATE `'. _DB_PREFIX_ .'product` SET `price` = ' .$sub_total. ' WHERE `id_product` = 9'); print_r($sub_total); echo "<form name='testForm' id='testForm' method='POST' > <Input type = 'Radio' Name ='install' id ='radio1'>DO Installation <Input type = 'Radio' Name ='install' id='radio2'>no <input type='submit' name='btn' autofocus /> </form>"; if(isset($_POST['install'])) { $params['cart']->updateQty(1, 9); $params['cart']->update(); } here is my code so far.. what it basically does is shows user an installation option. also it calculates cost for it from the db(saved already via the backend. ) then it makes that cost the price of a product 'installation' ive predefined and adds it to the cart this way if the user chooses installation option the relevant cost is added.. now a few doubts.. how to refresh the cart after update?? is there a way to use ajax-addcart here?? also how i get this form back down.. u can refer the below link for ref:: http://soccer-madness.com/presta/index.php?controller=order Edited July 3, 2014 by cyberdoc (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted July 3, 2014 Share Posted July 3, 2014 don't use echo there! use your .tpl file as you used it before. and just add there (in this hook) code like: if(isset($_POST['install'])) { $params['cart']->updateQty(1, 9); $params['cart']->update(); } and don't use action="" param in your <form> page will be reloaded - hook will be executed, and if condition will be executed too Link to comment Share on other sites More sharing options...
cyberdoc Posted July 3, 2014 Author Share Posted July 3, 2014 just noticed it was the echo!! so i did the changes and it comes back to its position but POST not working correctly now it seems... Link to comment Share on other sites More sharing options...
vekia Posted July 4, 2014 Share Posted July 4, 2014 okay, so to verify it please use this: print_r($_POST); use it before return in your hook function do you see on your page while you post your form? Link to comment Share on other sites More sharing options...
cyberdoc Posted July 4, 2014 Author Share Posted July 4, 2014 fixed it... Here is the code!! if(isset($_POST['install'])=='on') { echo($_POST['install']); $params['cart']->updateQty(1, 9); $params['cart']->update(); header('Location: '. $_SERVER['PHP_SELF']); exit(); } return $this->display(__FILE__, 'views/frontend/sample.tpl'); } Link to comment Share on other sites More sharing options...
vekia Posted July 4, 2014 Share Posted July 4, 2014 so, i think, that whole topic is solved too ? ;-) Link to comment Share on other sites More sharing options...
cyberdoc Posted July 4, 2014 Author Share Posted July 4, 2014 yes and marked as solved too!! 1 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