0

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?

3
  • 1
    Have you considered using ivaynberg.github.io/select2/#tags or aehlke.github.io/tag-it ? Commented May 20, 2013 at 21:22
  • nope lemme check them out Commented May 20, 2013 at 21:28
  • Try select2 first as it's quite capable of doing pretty much everything. The GUI is great and the tags are stored in the input you attach select2 to. So when you submit the form you only need to process the input with php - something like $tags = explode(',', $_POST['tags']); foreach($tags as $tag) { //do some action } Commented May 20, 2013 at 21:31

1 Answer 1

1

you have to do an ajax request via jquery.

you can find a lot of tutorials on web how to do that (e.g. http://www.ibm.com/developerworks/opensource/library/os-php-jquery-ajax/)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.