I have a piece of php code that is submitting data to a database. Prior to that I do validation on other fields. If there are missing fields, I throw an error and echo the post data back to those fields.
I am using a jQuery plugin as well and need to send that data back the the plugin to re-invoke the tags.
$("#tags").select2({
tags: <?php if(isset($_POST['action'])) {
if ($_GET['action'] != 'success'){
echo $_POST['tags']; }
}else{
echo '[]';
} ?>,
minimumInputLength: 3,
tokenSeparators: [",", " "]
});
It needs to be in this format:
["tag1", "tag2", "tag3"]
How can I achieve this from a comma separated string? tag1,tag2,tag3