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 <[email protected]> * @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 –
6 comments
‘submit’ => array(‘title’ => $this->l(‘Save’)),
‘buttons’ => array(
array(
‘title’ => $this->l(‘Back’),
‘icon’ => ‘process-icon-back’,
‘href’ => ‘YOUR_ADMIN_CONTROLLER_LINK’,
‘class’ => ‘btn btn-default’
)
)
Here how will you retrieve and show the values stored in the database?
I tried this but configuration values are not showing in the form?
For example, If you used this –
‘PS_NAME’ => array(
‘title’ => $this->l(‘Customer Name’),
‘type’ => ‘text’,
),
then customer name will save in PS_NAME configuration name and it will automatically get data by this name.
You don’t need to add any code for retrieving data.