1

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

<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 , dont forget to remove cookie after form submition. then you can access cookies in php `$_COOKIE('cookie_name');` – Noman Sep 28 '16 at 05:36
  • @Noman ok i will try that –  Sep 28 '16 at 05:39
  • is there any possible way to accomplish using local strorage –  Sep 28 '16 at 08:58
  • local storage are use for `client-side` for more details read [here](http://stackoverflow.com/questions/3220660/local-storage-vs-cookies?answertab=active#tab-top) – Noman Sep 28 '16 at 09:10
  • @Noman thanks for your further help –  Sep 28 '16 at 10:14
  • @Noman make your comment into answer,as it was helpful . i got my solution. i also reffered this http://stackoverflow.com/questions/7086989/jquery-and-php-cookies –  Sep 28 '16 at 10:40
  • Please check :) – Noman Sep 28 '16 at 10:47

1 Answers1

0

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');
Community
  • 1
  • 1
Noman
  • 4,088
  • 1
  • 21
  • 36