EaBangalore EaBangalore - 26 days ago 5x
Javascript Question

how to get select2(plugin) tag value in php

I'm using select2 plugin.

I'm able to get the selected tags array in jquery,but how can I append array into the DOM and get values in php on form submission or any other methods?

There are multiple file uploads in my form so I don't want ajax.
Here is a tag on which I'm applying


<input type="hidden" id="tags" value="tag" style="width: 400px;">

Here is a fiddle I'm using: http://jsfiddle.net/X6V2s/66/

I have an array of values in jquery but want it in php.

can i append array into DOM(if yes then?how)

How could I accompolish this ?
Please help me.
Thanks in advance.


try setting cookies of selected tags before submitting a form. then you can access cookies in php

NOTE: dont forget to remove cookie after form submition.

JS: using jQuery Cookie For further understating about JQuery cookie read here

$.cookie("test", 1, {
   expires : 10,           //expires in 10 days

   path    : '/',          //The value of the path attribute of the cookie 
                           //(default: path of page that created the cookie).

   domain  : 'yourdomain.com',  //The value of the domain attribute of the cookie
                           //(default: domain of page that created the cookie).

   secure  : true          //If set to true the secure attribute of the cookie
                           //will be set and the cookie transmission will
                           //require a secure protocol (defaults to false).

PHP Read cookie on server-side.

echo $_COOKIE('test');