Amit8146 Posted September 16, 2014 Share Posted September 16, 2014 Hi, I am new in prestashop. I am trying to develop a simple module. Two text box on front end 1.Name, 2. Phone no. Two value will inserted in database. I have't get value from front end tpl file. And my module was working fine through back end panel. My mymodule.php file like this <?php /* * */ if(!defined('_PS_VERSION_')) exit; class MyModule extends Module { /** @var max image size */ protected $maxImageSize = 307200; public function __construct() { $this->name = 'mymodule'; $this->tab = 'front_office_features'; $this->version = '0.0.1'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Mymodule'); $this->description = $this->l('Mymodule.'); $this->confirmUninstall = $this->l('Are you sure to uninstall Mymodule?'); } public function install() { if (!parent::install() || !$this->installDB() || !$this->registerHook('home') || !$this->registerHook('header')) return false; return true; } public function installDB(){ if (!Db::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'storewhatapps` ( `store_id` int(10) unsigned NOT NULL auto_increment, `name` varchar(255) NOT NULL, `phone_num` int(15) NOT NULL, PRIMARY KEY (`store_id`)) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8')) return false; return true; } public function uninstall() { if (!parent::uninstall() || !$this->uninstallDB()) return false; return true; } public function getContent() { $name=Tools::getValue('name'); $phone_number=Tools::getValue('phone_number'); if (Tools::isSubmit('submit_details')) { if(Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'storewhatapps` (`store_id`, `name`, `phone_num`) VALUES ("","'.$name.'","'.$phone_number.'")')) { $this->_html .=$this->displayConfirmation($this->l('Settings updated successfully')); } else { $this->_html .= $this->displayError($this->l('You Have Some Errors')); } } //$this->_displayForm(); $this->display(__FILE__, 'mymodule.tpl'); //return $this->_html; return $this->display(__FILE__, 'mymodule.tpl'); } public function hookHome($params) { return $this->display(__FILE__, 'mymodule.tpl'); } public function hookHeader() { $this->context->controller->addCSS(($this->_path).'css/store_styles.css', 'all'); } } And my mymodule.tpl file look like this <fieldset> <form id="formID" method="post" action="#"> <p> <label for="name">Name:</label> <input id="name" name="name" type="text"/> </p> <p> <label for="phone_number">Phone Number:</label> <input id="phone_number" name="phone_number" type="text" /> </p> <p> <label> </label> <input type="submit" name="submit_details" class="button" /> </p> </form> </fieldset> Please guide me Link to comment Share on other sites More sharing options...
vekia Posted September 16, 2014 Share Posted September 16, 2014 and where the problem is? why you use the same .tpl file both for front and back office? Link to comment Share on other sites More sharing options...
Amit8146 Posted September 17, 2014 Author Share Posted September 17, 2014 My problem is how I use the front tpl. In this present code the data is inserted from backend successfully. But when I insert data from front end is not inserted. Please help me. How can insert from front end. Link to comment Share on other sites More sharing options...
vekia Posted September 17, 2014 Share Posted September 17, 2014 to insert data from front office whole php script that controlls saving process must be a part of hook so whole script: if (Tools::isSubmit('submit_details')) { if(Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'storewhatapps` (`store_id`, `name`, `phone_num`) VALUES ("","'.$name.'","'.$phone_number.'")')) { $this->_html .=$this->displayConfirmation($this->l('Settings updated successfully')); } else { $this->_html .= $this->displayError($this->l('You Have Some Errors')); } } + all variables must be a part of hookHome Link to comment Share on other sites More sharing options...
Amit8146 Posted September 17, 2014 Author Share Posted September 17, 2014 Thanks for your help. I added your code public function hookHome($params) { if (Tools::isSubmit('submit_details')) { if(Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'storewhatapps` (`store_id`, `name`, `phone_num`) VALUES ("","'.$name.'","'.$phone_num.'")')) { $this->_html .=$this->displayConfirmation($this->l('Settings updated successfully')); } else { $this->_html .= $this->displayError($this->l('You Have Some Errors')); } } return $this->display(__FILE__, 'mymodule.tpl'); } But when I have insert value from front end ...then it is the blank value in my DB. Please help. Link to comment Share on other sites More sharing options...
Amit8146 Posted September 17, 2014 Author Share Posted September 17, 2014 Sorry Actually I have missing the variable for get value. My final code is public function hookHome($params) { $name=Tools::getValue('name'); $phone_num=Tools::getValue('phone_num'); if (Tools::isSubmit('submit_details')) { if(Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'storewhatapps` (`store_id`, `name`, `phone_num`) VALUES ("","'.$name.'","'.$phone_num.'")')) { $this->_html .=$this->displayConfirmation($this->l('Settings updated successfully')); } else { $this->_html .= $this->displayError($this->l('You Have Some Errors')); } } return $this->display(__FILE__, 'mymodule.tpl'); } Its work fine now. Thanks for your help. Link to comment Share on other sites More sharing options...
vekia Posted September 17, 2014 Share Posted September 17, 2014 glad to hear that i could help a little i marked topic title as solved. with regards, Milos 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