How to create and submit a form using renderOptions of Prestashop Admin controller
In this blog, we will learn that how to create and submit a form using renderOptions() in any admin controller of Prestashop and also we will see that how we can display form in place of renderList.
So suppose we want to create a form with some fields ie. input fields, radio button etc. and we need to save these data in Prestashop `configuration` table.
Also this form will be display at the position of renderList of your Admin controller.
So here is the code through we can create a form in any admin controller using renderOptions() in place of renderList.
/**
* 2010-2017 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2017 Webkul IN
* @license https://store.webkul.com/license.html
*/
public function __construct()
{
$this->context = Context::getContext();
$this->bootstrap = true;
$this->table = 'configuration';
parent::__construct();
$this->fields_options = array(
'Form' => array(
'title' => $this->l('Form'),
'icon' => 'icon-cogs',
'fields' => array(
'PS_NAME' => array(
'title' => $this->l('Customer Name'),
'type' => 'text',
),
'PS_EMAIL' => array(
'title' => $this->l('Customer Email'),
'type' => 'text',
),
'PS_DISPLAY_DETAILS' => array(
'title' => $this->l('Display Customer Details'),
'type' => 'bool',
'validation' => 'isBool',
'default' => '1'
),
),
'submit' => array('title' => $this->l('Save'))
),
);
}
Normally we use $this->fields_list for showing renderList in Admin controller __construct() function but here we will use $this->fields_options. So that we can display our form instead of renderList.
After this we can see form in our admin controller –