Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST variable naming error #172

Open
LLFT opened this issue Jun 19, 2020 · 1 comment
Open

POST variable naming error #172

LLFT opened this issue Jun 19, 2020 · 1 comment

Comments

@LLFT
Copy link

LLFT commented Jun 19, 2020

Hello,
On the following code:


<select name="Gauche[]" class="duallistbox" id="inputSelectGroup" multiple="multiple" size="20" >

<optgroup label="Grp1">
<option selected="selected" value="1">option 1</option>
<option selected="selected" value="2">option 2</option>
</optgroup>
<optgroup label="Grp2">
<option selected="selected" value="3">option 3</option>
<option selected="selected" value="4">option 4</option>
</optgroup></select>

<script src="./plugins/bootstrap4-duallistbox/jquery.bootstrap-duallistbox.js"></script>
<script>
    $(function () {
        $('.duallistbox').bootstrapDualListbox({
            preserveSelectionOnMove: 'moved',
            moveOnSelect: false,
        });
    });
</script>


After deselecting option 1 and validating the form we get the table:

Debug Chrome : 
	Gauche[]_helper2: 1
	Gauche[]: 2
	Gauche[]: 3
	Gauche[]: 4

PHP $_POST 
[Gauche] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
            [3] => 4
        )

The variable is therefore false.

Correcting the code at setHelperSelectNamePostfix like this:

setHelperSelectNamePostfix: function(value, refresh) {
      this.settings.helperSelectNamePostfix = value;
      if (value) {
        this.elements.select1.attr('name', this.originalSelectName.replace('[]','') + value + '1[]');
        this.elements.select2.attr('name', this.originalSelectName.replace('[]','') + value + '2[]');
      } else {
        this.elements.select1.removeAttr('name');
        this.elements.select2.removeAttr('name');
      }
      if (refresh) {
        refreshSelects(this);
      }
      return this.element;
    },

We get the table:

Debug Chrome : 
	Gauche_helper1[]: 1
	Gauche[]: 2
	Gauche[]: 3
	Gauche[]: 4

PHP $_POST :

    [Gauche_helper2] => Array
        (
            [0] => 1
        )

    [Gauche] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 4
        )
@joegrcs
Copy link

joegrcs commented Oct 29, 2021

I think I fixed the problem with using this plugin with PHP. I modified the following lines,
Around line 43
helperSelectNamePostfix: 'helper_',
// Original Line Below
// helperSelectNamePostfix: '_helper', // 'string_of_postfix' / false

Around Line 653
this.elements.select1.attr('name', value + '1_' + this.originalSelectName);
this.elements.select2.attr('name', value + '2_' + this.originalSelectName);
// Below are original Lines
// this.elements.select1.attr('name', this.originalSelectName + value + '1');
// this.elements.select2.attr('name', this.originalSelectName + value + '2');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants