Jump to content

Checkbox HelperForm - Post values


strejcz

Recommended Posts

Hello,
 
long time solves the problem through HelperForm checkbox. They need to retrieve the category checkbox, set the following values ​​checkbox and send those values​​.
 
I get an array of categories from the following command:
$cats = Category::getCategories((int) ($cookie->id_lang), true, false);

Proceed as follows to entry and all entries category I get the checkbox

array(
  'name'    => 'cat[]',
  'type'    => 'checkbox',
  'label'   => $this->l('Categories'),
  'values'  => array(
    'query' => $cats,
    'id'    => 'id_option',
    'name'  => 'name',
  ),
),

The problem comes when I want to sent selected value use.

var_dump($_POST['cat']);

OUT:
array (size=2)
  0 => string 'on' (length=2)
  1 => string 'on' (length=2)

I found a solution if the item you manually:

array(
                    'name' => 'displayAll[]',
                    'type' => 'checkbox',
                    'values' => array(
                        'query' => array(
                            array(
                                'id' => 'on',
                                'name' => $this->l('1'),
                                'val' => '11'
                            ),
                            array(
                                'id' => 'on',
                                'name' => $this->l('2'),
                                'val' => '22'
                            ),
                            array(
                                'id' => 'on',
                                'name' => $this->l('3'),
                                'val' => '33'
                            ),
                        ),
                        'id' => 'id',
                        'name' => 'name'
                    )
                ),
var_dump($_POST['displayAll']);

OUT
array (size=2)
  0 => string '11' (length=2)
  1 => string '33' (length=2)

I do not know how can I combine them so I can retrieve the value and the name and send the variables:

$cats = Category::getCategories((int) ($cookie->id_lang), true, false);
I tried all combinations nmožné, unfortunately I failed.
 
Thank you for any advice
Link to comment
Share on other sites

  • 1 year later...
/*categories*/

$cats = Category::getCategories($this->context->language->id, true, false);

 

 

foreach($cats as $key => $cat)

{

$categories[] = array('id_option' => $cat['id_category'], 'name' => $cat['name']);

}

 

 

and in the form to get cats:

 


array(

'type' => 'checkbox',

'label' => $this->l('Shop category to filter the PDF'),

'name' => 'skipcat',

'class' => 't',

'multiple' => true,

'values' => array(

'query' => $categories,

'id' => 'id_option',

'name' => 'name',

'expand' => array(                      // 1.6-specific: you can hide the checkboxes when there are too many.

                                             // A button appears with the number of options it hides.

    'print_total' => count($categories),

    'default' => 'show',

    'show' => array('text' => $this->l('show'), 'icon' => 'plus-sign-alt'),

    'hide' => array('text' => $this->l('hide'), 'icon' => 'minus-sign-alt')

  ),

)

),

Link to comment
Share on other sites

  • 4 months later...

This topic helped me a lot, but I still can't save any datas in my SQL....

 

I'm trying to developp a module where It could be possible to select 6 categories to display in specific hooks on my website. For now, i'm trying to save the values of checkbox in my BO in my database.

 

I'd like to be able to save the id of selected categories in a row :

 

For exemple if I select 2 catégories as follow :

[_] Catégory 1

[X] Catégory 2

[_] Catégory 3

[X] Catégory 4

 

The result sent to my database shoud be :

2, 4.

 

This way I will launch a loop in front office in order to get thumbnails, title and link.

 

Any ideas please ?? :)

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...