tibdev Posted September 12, 2018 Share Posted September 12, 2018 (edited) Hello, I try to submit my form but no action happens and when I press the submit button, a green message at the top right saying setting update is displayed. here is my main file <?php require dirname(__FILE__) . '/controllers/admin/AdminMoreProduct.php'; if (!defined('_PS_VERSION_')) { exit; } class MoreProduct extends Module { public function __construct() { //description module $this->name = 'moreproduct'; $this->tab = 'administration'; $this->version = '1.0'; $this->author = 'Thibaut'; //enabled config $this->bootstrap = true; $this->need_instance = 0; //$this->controllers = array('moreProduct'); //display parent::__construct(); $this->displayName = $this->l("MoreProduct"); $this->description = $this->l('add more product for product'); } public function install() { $this->createDb(); $this->installModuleTab(); return parent::install() && $this->registerHook('header') && $this->registerHook('displayAdminProductsExtra') && $this->registerHook('actionProductUpdate'); } public function uninstall() { return $this->uninstallModuleTab() && parent::uninstall() && $this->removeDb(); } public function installModuleTab() { $tab = new Tab(); $langs = language::getLanguages(); foreach($langs as $l) { $tab->name[$l['id_lang']] = "MoreProduct"; } $tab->module = $this->name; $tab->id_parent = 0; $tab->active = 1; $tab->class_name = "AdminMoreProduct"; if (!$tab->save()): return $this->_abortInstall($this->l('Unable to create the "Admin MoreProduct" tab')); endif; } public function uninstallModuleTab() { $idTab = Tab::getIdFromClassName('AdminMoreProduct'); if($idTab) { $tab = new Tab($idTab); return $tab->delete(); } return true; } //DB public function createDb() { $query = " create table ps_moreproduct ( id int(3) not null auto_increment, text_mp varchar(100), url_img varchar(100), url_puce varchar(100), id_product int(10) UNSIGNED, primary key(id), foreign key (id_product) references ps_product(id_product) ); "; return Db::getInstance()->query($query); } public function removeDb() { $query = 'DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'moreproduct;'; return Db::getInstance()->query($query); } //hook public function hookDisplayAdminProductsExtra($params) { $form = new AdminMoreProductController(); if(isset($params['id_product']) && (int)$params['id_product']) { $product = Db::getInstance()->ExecuteS(' select text_mp, url_img, url_puce, id_product from ' . _DB_PREFIX_ .'moreproduct where id_product = ' . $params['id_product'] . ';'); $this->context->smarty->assign(array( "product" => $product, "form" => $form->renderForm(), "bt" => $form->postProcess() )); } return $this->display(__FILE__ , 'views/templates/admin/moreProduct.tpl'); } public function hookActionProductUpdate($params) { } public function hookHeader() {} } My controller file : <?php require _PS_MODULE_DIR_.'moreproduct/classes/MoreProductTabClass.php'; class AdminMoreProductController extends ModuleAdminController { public function __construct() { $this->bootstrap = true; $this->allow_export = true; $this->table = 'MoreProduct'; $this->className = 'MoreProductTabClass'; parent::__construct(); $this->fields_list = array( 'id' => array( 'title' => $this->l('ID of more product'), 'align' => 'center', 'havingFilter' => true, ), 'text_mp' => array( 'title' => $this->l('text of product'), 'align' => 'center', 'havingFilter' => true, ), 'url_img' => array( 'title' => $this->l('image more product'), 'search' => false, 'align' => 'center', 'display_image' => true, 'prefix' => "<img src='../modules/moreproduct/img/", 'suffix' => "' width='100'>", 'havingFilter' => true, ), 'url_puce' => array( 'title' => $this->l('puce more product'), 'search' => false, 'align' => 'center', 'display_image' => true, 'prefix' => "<img src='../modules/ed_label_product/img/puce", 'suffix' => "' width='100'>", 'havingFilter' => true, ), ); } public function init() { parent::init(); } public function postProcess(){ $msg = ""; if(Tools::isSubmit('submitSendData')) { /*$tab = new MoreProductTabClass(); $tab->text_mp = Tools::getValue('text_mp'); $tab->url_img = Tools::getValue('url_img'); $tab->url_puce = Tools::getValue('url_puce'); $tab->id_product = Tools::getValue('id'); if(isset($_FILES['url_img'])) { $tab->url_img = $this->checkImg($_FILES['url_img'], '../modules/moreproduct/img/'); } else if(isset($obj->url_img)) { $obj->url_img = $tab->url_img; } else { $tab->url_img = null; } //SQL $sql = "insert into ps_moreproduct (text_mp, url_img, url_puce, id_product) values ('" . $tab->text_mp . "' , '" . $tab->url_img . "' , '" . $tab->url_puce . "' , " . $tab->id_product . "); "; $tab->save();*/ $msg = "submit button"; } return $msg; } public function renderForm() { $this->initToolbar(); $obj = $this->loadObject(true); $this->addJquery(); $this->addjQueryPlugin(array('scrollTo', 'alerts', 'chosen', 'autosize', 'fancybox', 'select2' )); $this->context->controller->addJS(_MODULE_DIR_.'/moreproduct/views/js/moreproduct.js'); $options = array( array( 'id_option' => 1, // The value of the 'value' attribute of the <option> tag. 'name' => 'test1', 'value' => 'test1' ), array( 'id_option' => 2, 'name' => 'test2', 'value' => 'test1' ), ); $this->fields_form = array( 'legend' => array( 'title' => $this->l('button more product'), 'icon' => 'icon-globe' ), 'input' => array( array( 'type' => 'text', 'class' => 'col-lg-6', 'id' => 'text_mp', 'name' =>'text_mp', ), array( 'type' => 'file', 'class' => 'col-lg-6', 'id' => 'url_img', 'name' =>'url_img', 'display_image' => true, ), array( 'type' => 'select', 'name' => 'url_puce', 'options' => array( 'query' => $options, 'id' => 'id_option', 'name' => 'name' ) ), ), 'submit' => array( 'title' => $this->module->l('Send Data'), 'name' => 'submitSendData', 'id' => 'submitSendData', 'class' => 'btn btn-primary', ), ); $helper = new HelperForm(); return parent::renderForm(); } public function checkImg(String $img,String $destination) { $newName = false; $allowed = array('image/gif', 'image/jpeg', 'image/jpg', 'image/png'); $tmpFile = $_FILES[$img]['tmp_name']; $nameFile = $_FILES[$img]['name']; if (!empty($img)) { if(!is_uploaded_file($tmpFile) ) { exit("Le fichier est introuvable"); } if(in_array($img['type'], $allowed)) { $newName = md5($img['name'] . time()) . "." . explode("/", $img['type'])[1]; $path = $destination . $newName; if(!move_uploaded_file($tmpFile, $path) ) { exit("Impossible de copier le fichier dans " . $destination); } } else { exit("Le fichier n'est pas une image"); } } return $newName; } } my view : {$bt|@var_dump} <form action="" method="post"> {$form} </form> <hr> <table class="table"> <thead> <tr> <th scope="col">content</th> <th scope="col">image</th> <th scope="col">icon used</th> </tr> </thead> <tbody> {if count($product) > 0} {foreach from=$product item=p} <tr> <td>{ $p['text_mp'] }</td> <td><img src="/modules/moreproduct/img/{$p['url_img']}" alt=""></td> <td><img src="/modules/moreproduct/img/{$p['url_puce']}" alt=""></td> </tr> {/foreach} {else} <div class="alert alert-danger" role="alert"> not data on table moreproduct </div> {/if} </tbody> </table> Please help me Edited September 12, 2018 by tibdev (see edit history) 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