Jump to content

[PS 1.7] module Helper Form


Guest

Recommended Posts

Hi to all,
nowhere I found a good example of how to create buttons according to a database table.
I have a ps_rarrier_lang table, I will add a column to it when I install the module

$my_query = 'ALTER TABLE '._DB_PREFIX_.'carrier_lang ADD `my_button` INT NOT NULL DEFAULT '0' AFTER `delay`;
Db::getInstance()->Execute($my_query);

And now I need to create a form where I can create all the fields according to another SQL query.
E.g.

$select_carrier = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'carrier_lang WHERE id_lang = '.$this->context->language->id.' ORDER BY id ASC');

And finally comes the creation of a form that I need to explain.
Save the ps_carrier_lang table to the database and retrieve it from the ps_carrier_lang database.
E.g.

public function renderForm()
    {
        $fields_form = array();

        $fields_form[0]['form'] = array(
            'legend' => array(
                'title' => $this->l('test'),
                'icon' => 'icon-cogs',
            ),
            'input' => array(
array(
                    'type' => 'switch',
                    'label' => $this->l(read in query array),
                    'name' => ' read in array id_carrier',
                    'required' => false,
                    'is_bool' => true,
                    'values' => array(
                        array(
                            'id' => 'active_on',
                            'value' => 1,
                            'label' => $this->l('Enabled'),
                        ),
                        array(
                            'id' => 'active_off',
                            'value' => 0,
                            'label' => $this->l('Disabled'),
                        ),
                    ),
                ),

Thank you all in advance.

I think such a demonstration will help a lot of beginning programmers.

 

I uploaded the project with notes as an attachment.

testmodule.php

Edited by Guest (see edit history)
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...