Jquery UI Dialog只工作一次?

As I said on my previous post, I have this bit of php code:

EDIT: I pasted the wrong code, corrected.

<?php
$posts = new Posts();

foreach($posts->getPosts() as $post){ ?>
    <div class="post">
        <h3><a class="post-link" data-post-id="<?php echo $post['id']; ?>" href="javascript:void(0)"><?php echo $post['title']; ?></a></h3>
    </div>

<?php } ?>

<div id="insert-answer" title="Add new idea to post">
<form id="myForm" action="insertidea.php" method="post">
    <fieldset>
        <p><label for="idea">Your idea:</label>
            <input type="text" name="idea" class="idea"</p>
        <p><label for="pic">Have a pic? Paste its URL here! (optional)</label>
            <input type="text" name="pic" class="pic"></p>
        <input type="hidden"class="author" name="author" value="<?php echo $_SESSION['google_data']['id']; ?>" />
        <input type="hidden"class="forpost" name="forpost" value="<?php echo $post['id']; ?>" />
    </fieldset>
</form>

And I have a form that pops up from each post's link:

$( "#insert-answer" ).dialog({
    autoOpen: false,
    modal:true,
    buttons: {
        "Add idea": function() {
            var forpost = $("#insert-answer").data("post-id"),
                author = $("#author").val(),
                idea = $(".idea").val(),
                pic = $(".pic").val();

            $.post('insertidea.php',{
                forpost: forpost, author: author, idea: idea, pic: pic, action:'joined'
            });//End Post

            $("#insert-answer").val('');
            $(".pic").val('');

            $(this).dialog("close");
        },

        Cancel: function() {
            $( this ).dialog( "close" );
        }
    }
});

$( ".post-link" ).on('click', function() {
    var postid = $(this).data("post-id");
    var answer = $("#insert-answer");
    $(answer).data('post-id', postid);
    $(answer).dialog( "open" );
});

So the user is supposed to be presented with a list of post, each post has a link that pops up the dialog that in turn contains a form that sends data to a mysql database trough another php file via post and it works fine, just only the first time. The second time I get some syntax errors and according to firebug, it comes from the array that is sent to the php file. I'm suspecting my dialog function is incomplete, do I need to "unset" anything after the data is sent? How would I accomplish that?

Thanks a lot!