I want to insert these particular tags into the database. This is my HTML:
<div id="tags">
<input type='text' name='tags' placeholder='Type in topic tags here seperated by commas' id="tagg" />
</div>
and the jQuery part:
counter = 0;
$(function(){
$('#tags input').on('focusout',function(){
var txt= $.trim( $(this).val() ).replace(',','');
if(txt){
$(this).before('<span class="tag" name="tags[]" value="'+txt+'">'+txt+'</span>');
counter++;
if(counter==5){
$('#tags input').prop('disabled', true);
}
//$(".bgtopic").append("<input type='hidden' name='tags[]' />")
//Yet to implement the counter varibale to be visible...
}
$(this).prop('value','');
}).on('keyup',function( e ){
if(e.which==188){
$(this).focusout();
}
});
$('#tags').on('click','.tag',function(){
$(this).remove();
counter--;
$('#tags input').prop('disabled', false);
});
});
What the piece of code creates a tag when a user is creating a new post on my forum, just like the way it is here on StackOverflow. I want to be able to store the tags so that I can use them to create a tag cloud. How can I accomplish this?
select2first as it's quite capable of doing pretty much everything. The GUI is great and the tags are stored in theinputyou attachselect2to. So when you submit the form you only need to process theinputwith php - something like$tags = explode(',', $_POST['tags']); foreach($tags as $tag) { //do some action }