How to mount an array with bootstrap taginput values?

1

I'm using a bootstrap tagsinput to insert values into bd, but values are being stored in a single string, for example: "256,257,299". I would like these values to be defined in an array and look like this: ["256", "257", "299"], then I give a foreach and each value goes to its proper place in bd. As it is today, all in a single string only the first id is being sent to the bd.

Does anyone know how to do this?

This is my input:

<input type="text" id="taginput" data-role="tagsinput" name="idrelacionado[]"> 

Thank you for your attention!

    
asked by anonymous 28.10.2016 / 23:05

3 answers

2

How I solved the problem:

In my form I have the following input ( tagsinput ):

<input type="text" data-role="tagsinput" name="idrelacionado"> 

I get this string in the following variable:

$idrelacionado = $_POST['idrelacionado'];

I apply the explode to the variable that stores the string, where the delimiter is the comma, "" and I store it in another variable.

$idre = explode(',', $idrelacionado);

Then just give a foreach on the variable that stores the explode.

    
01.11.2016 / 20:32
0

Ready, what a Google does not solve.

"Php split deprecated what to use instead" link

UPDATE

Done, another Google and found your answer, link

Like any jQuery component, you can do "magic" with JavaScript.

As you can see, the first page already has what you need.

$("input").tagsinput('items')

Calling the items method of your component tagsinput returns you the values in an array.

    
29.10.2016 / 00:38
0

Hello, I had the same problem and the solution was not any of the ones presented here and I did not google search for it, I was almost using another script, when I was implementing it, I saw that it uses the select field instead of input, so I thought pow the solution was just put the field as select aidionei the items in js and put the coxetes in the name of the field and worked, then let's go the step by step ..

Javascript

tagsinput('items');

HTML

<div class="form-group">
<label>Campo Array</label><br>
<select name="NomeCampoArray[]" data-role="tagsinput" multiple="multiple" multiple data-placeholder="Digite as tags separadas..." value="<?php print_r($NomeCampoArray);?>">
<optgroup label="NomeCampoArray">
</select>
</div>
    
15.04.2017 / 22:11