prestashop_newuser Posted March 11, 2014 Share Posted March 11, 2014 (edited) Hi, I am doing a small module in prestashop 1.6. In the module I have the code something like this public function getContent() { $site_url = Tools::getValue('FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')); if (Tools::isSubmit('submit')) { if (empty($_POST['FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')])) $this->_html .= $this->displayError($this->l('You must fill the field.')); else { if(Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'mymodule`(`module_id`,`site_url`) VALUES ("","'.$site_url.'")')) { $this->_html .= $this->displayConfirmation($this->l('Settings updated.')); } else { $this->_html .= $this->displayError($this->l('You have some errors.')); } } } } This one is doing insert the values to the database. But when I am doing validate the module in prestashop validator it is showing error like this The use of $_POST is forbidden; use Tools::getValue() instead But when I tried to solve the error by its suggestion with this code public function getContent() { $site_url = Tools::getValue('FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')); if (Tools::isSubmit('submit')) { if (empty(Tools::getValue('FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')))) $this->_html .= $this->displayError($this->l('You must fill the field.')); else { if(Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'mymodule`(`module_id`,`site_url`) VALUES ("","'.$site_url.'")')) { $this->_html .= $this->displayConfirmation($this->l('Settings updated.')); } else { $this->_html .= $this->displayError($this->l('You have some errors.')); } } } } it is showing error like Fatal error: Can't use function return value in write context So can someone kindly tell me how to solve this issue? Any help and suggestions will be really appreciable. Thanks Edited March 12, 2014 by prestashop_newuser (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 11, 2014 Share Posted March 11, 2014 i don't see any $_POST variable in your first code Link to comment Share on other sites More sharing options...
prestashop_newuser Posted March 12, 2014 Author Share Posted March 12, 2014 i don't see any $_POST variable in your first code @Vekia ..sorry there was a problem in typo. Now I have updated my question. You can now check the question. Link to comment Share on other sites More sharing options...
vekia Posted March 12, 2014 Share Posted March 12, 2014 ok i see now if (empty($_POST['FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')])) so, you used: if (empty(Tools::getValue('FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')))) Tool::getValue function returns: - if variable exists: value of variable (from post, get etc.) - if variable doesnt exist: it returns false(bool) so it can't be "empty" if i vere you i will use if condition like: if (Tools::getValue('FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')) !=false) Link to comment Share on other sites More sharing options...
prestashop_newuser Posted March 20, 2014 Author Share Posted March 20, 2014 ok i see now if (empty($_POST['FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')])) so, you used: if (empty(Tools::getValue('FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')))) Tool::getValue function returns: - if variable exists: value of variable (from post, get etc.) - if variable doesnt exist: it returns false(bool) so it can't be "empty" if i vere you i will use if condition like: if (Tools::getValue('FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')) !=false) @Vekia thanks for the answer. I just changed your code like this if (Tools::getValue('FACEBOOKACTIVITY_URL_'.Configuration::get('PS_LANG_DEFAULT')) !=true) and it worked. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts