Save Select2 tags via post to php

Asked

Viewed 309 times

1

Hello, I would like to know how to send a POST with the tags selected in the select2 (version 4). My code works perfectly, but I cannot send the result of tags selected for the server php, soon none of them will be saved.

The data is remote, which made my attempts even more difficult. The goal would be to pass the data via POST at the php that would save them by separating the values by , Ex: valor1, valor dois, etc

Currently I use the x-editable with php to save the data, but my select2 currently used get the data dynamically and could not integrate the two.

JSON DATA

{ "items": [{"text":"Meu Nome","id":"xyz05410"}]}

HTML

<select class="js-data-example-ajax" multiple="multiple"
style="width: 100%" class="form-control select2"></select>

JS

$(".js-data-example-ajax2").select2({
  ajax: {
    url: "get_data.php",
    dataType: 'json',
    delay: 250,
    data: function (params) {
      return {
        term: params.term // search term
      };
    },
    processResults: function (data, page) {
      return {
        results: data.items
      };
    },
    cache: true
  },
  //tags: true,
  theme: "bootstrap",
  tokenSeparators: [","],
  allowClear: true,
  placeholder: 'Insert tags',

  escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
  minimumInputLength: 3,
  templateResult: formatRepo, // omitted for brevity, see the source of this page
  templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
});

Are there any way to save the selected tags from select2(v4) in php?

  • Any help is welcome, leave in the comments, gender references, so that they can help me and those looking for relevant information.

1 answer

-2

Hey, buddy, after all this time, you might not need it anymore, but I’m gonna post it anyway. It was with the same problem, I just solved added [] in the select name.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.