Jump to content

[SOLVED] How to make nice looking form in back office


theillo

Recommended Posts

With the help of the module generator https://validator.prestashop.com/generator I created a module, which gives me a generic config page. This config page combines a template and a helper form.

 

Looks like this:

mVInRZy.png

 

really nice and everything, right?

 

Now I tried to create an Admin controller, and display the same form in my admin controller.

It works alright, but it doesn't look the same:

 

ZDc9XlB.png

 

What do I have to do for this page to get the same look as the default config page? O_o *clueless*

Edited by vekia (see edit history)
Link to comment
Share on other sites

Thanks man, this did the trick! I also appreciate the link you posted, it's a good guide on how to use the helper forms!

 

Here's my controller:

<?php

class AdminTestModuleController extends ModuleAdminController
{
	public function __construct()
	{
		$this->bootstrap = true;
		$this->display = 'Test you Module';
		$this->meta_title = $this->l('Test Module');
		parent::__construct();
	}
	
	public function getFieldsValues()
	{
		return array(
			'some_live_mode' => true,
			'some_email' => 'email',
			'some_password' => 'password'
		);
	}	

	protected function getFormFields()
	{
		return array(
			'form' => array(
				'legend' => array(
				'title' => $this->l('Settings'),
				'icon' => 'icon-cogs',
				),
				'input' => array(
					array(
						'type' => 'switch',
						'label' => $this->l('Live mode'),
						'name' => 'some_live_mode',
						'is_bool' => true,
						'desc' => $this->l('Use this module in live mode'),
						'values' => array(
							array(
								'id' => 'active_on',
								'value' => true,
								'label' => $this->l('Enabled')
							),
							array(
								'id' => 'active_off',
								'value' => false,
								'label' => $this->l('Disabled')
							)
						),
					),
					array(
						'col' => 3,
						'type' => 'text',
						'prefix' => '<i class="icon icon-envelope"></i>',
						'desc' => $this->l('Enter a valid email address'),
						'name' => 'some_email',
						'label' => $this->l('Email'),
					),
					array(
						'type' => 'password',
						'name' => 'some_password',
						'label' => $this->l('Password'),
					),
				),
				'submit' => array(
					'title' => $this->l('Create'),
				),
			),
		);
	}	
	
	public function renderForm()
	{
		$helper = new HelperForm();
		$helper->show_toolbar = true;
		$helper->table = $this->table;
		$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
		$helper->default_form_language = $lang->id;
		$helper->allow_employee_form_lang =
			Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
		$this->fields_form = array();
	 
		$helper->identifier = $this->identifier;
		$helper->submit_action = 'submitBlockCart';
		$helper->currentIndex = $this->context->link->getAdminLink('AdminTestModuleController', false);
		$helper->token = Tools::getAdminTokenLite('AdminModules');
		$helper->tpl_vars = array(
			'fields_value' => $this->getFieldsValues(),
			'languages' => $this->context->controller->getLanguages(),
			'id_language' => $this->context->language->id
		);
	 
		return $helper->generateForm(array($this->getFormFields()));
	}
	
	public function display()
	{
		$this->context->smarty->assign(array(
			'test_module_form' => $this->renderForm()
		));
		parent::display();
	}
	
	public function postProcess()
	{
		if (Tools::isSubmit('submitConfigForm'))
		{
			//things to do on submit.
		}
		parent::postProcess();
	}
}
  • Like 2
  • Thanks 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...