I've developped a prestashop module that display a form, and now I want to use the POST data to store my data in the database.
Following some tutorials I'm able to display the form and load some js file, but my question are two:
What will be the action parameter of my form?
How can i handle the post parameters, and where??
The structure of my module is this - root is /modules/mymodule/ dir:
mymodule.php
/views/templates/hook/mymodule.tpl
/views/js/front.js
Have i to insert a controller??
Thank you.
EDIT- Add some code
mymodule.php
class MyModule extends Module
{
public function __construct()
{
$this->name = 'mymodule';
$this->controllers = array( 'display' ); // <- my controller name
parent::__construct();
}
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
if (!parent::install() ||
!$this->registerHook('customCMS') ||
!$this->registerHook('header')
)
return false;
return true;
}
public function hookcustomCMS($params)
{
if (Tools::getValue('id_cms') != 7)
return;
$this->context->smarty->assign(
array(
'form_link' => $this->context->link->getModuleLink('mymodule', 'display')
)
);
return $this->display(__FILE__, 'mymodule.tpl');
}
}
mymodule.tpl
<form id="myform" action="{$link->getModuleLink('mymodule', 'display')|escape:'html'}" method="post">
<!-- all fields... + submit button -->
</form>
display.php (this shoul be the controller in mymodule/controllers/front)
<?php
class mymoduledisaplyFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
$this->context->controller->addJS($this->module->getLocalPath().'views/js/front.js');
$this->setTemplate('mymodule.tpl');
}
public function postProcess()
{
if (Tools::isSubmit('submit_requestform'))
{
// form processing
ppp("OK");
}
}
}
That's all...