I am using jquery.webspirited.coms tagit jquery, which is working correctly in the sense of creating the tags, separating on the front end, but when I POST the data, it's only posting the last tag as the value to the database..
I can't find any documentation on how to correctly install the addon apart from what code to put in the header etc, here is the header code.
<script type="text/javascript">
$(function () {
$('#topic').tagit();
$('#topicGetTags').click(function () {
showTags($('#topic').tagit('tags'))
});
$('input[type=submit]').click(function(){
tag = $('#topic').tagit('tags');
console.log(tag);
for (var i in tag)
$('form').append("<input type='hidden' name='tags[]' value='"+tag[i].value+"' >");
});
function showTags(tags) {
console.log(tags);
var string = "Tags (label : value)\r\n";
string += "--------\r\n";
for (var i in tags)
string += tags[i].label + " : " + tags[i].value + "\r\n";
alert(string);
}
});
</script>
The input
<ul id="topic" name="tags[]"></ul>
The tagit.js file itself has almost 500 lines, so rather than copy/paste it here, here is a link to it.
http://webspirited.com/tagit/js/tagit.js
Also here is the INSERTION code, incase it's something I need to look at there
$tags = isset($_POST['tags']) ? $_POST['tags'] : null;
if (is_array($tags)) {
foreach ($tags as $t) {
// escape the $t before inserting in DB
$sql = "INSERT INTO tags (tags) VALUES('$t')";
}
Thanks for any tips