• Hi there,

    I have this function in functions.php:

    function voteaza_lucrare( $comm_post_id, $comm_author, $comm_email, $comm_content, $userID )
    {
    		$time = current_time('mysql');
    
    		$data = array(
    			'comment_post_ID' => $comm_post_id,
    			'comment_author' => $comm_author,
    			'comment_author_email' => $comm_email,
    			'comment_author_url' => 'http://startut.ro',
    			'comment_content' => $comm_content,
    			'comment_type' => '',
    			'comment_parent' => 0,
    			'user_id' => $userID,
    			'comment_author_IP' => '127.0.0.1',
    			'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
    			'comment_date' => $time,
    			'comment_approved' => 1,
    		);
    
    		wp_insert_comment($data);
    }

    This function will add a comment to a post, work perfect, but…

    I try to use this function in comment-template.php for the link of a button:

    <div style="float: right;"><a href="<?php voteaza_lucrare(get_the_ID(), $current_user->user_login, $current_user->user_email, 'Vot ' . get_comment_author , $current_user->ID ); ?>" class="button facebook"><font color="#ffffff">Votează această lucrare</font></a></div>

    The problem is that when I go to a post, will add automatically comments, and I want to add a comment only when I click that button.

    I try with onclick event, but nothing, or I don’t use the event correctly.

    Thanks.

The topic ‘Problem with add a comment with a button’ is closed to new replies.