Store comment form custom field in custom database

I'm trying to add custom field created on comment form to custom database.But my solutions not working. How to chan

I'm trying to add custom field created on comment form to custom database.

But my solutions not working. How to change/improve it?

I add custom fields this way:

function add_interests( $fields ) {

    $fields[ 'interest_1' ] =
        '<p class="comm-chbox">
        <input type="checkbox" name="interest_1" id="interest_1">
        <label for="interest_1">Are you interested in ...?</label>
        </p>';


    $fields[ 'interest_2' ] =
        '<p class="comm-chbox">
        <input type="checkbox" name="interest_2" id="interest_2">
        <label for="interest_2">Are you interested in ...?</label>
        </p>';

    return $fields;
}

add_filter( 'comment_form_default_fields', 'add_interests' );

I'm trying to use comment_post hook.

function save_interests() {

    global $wp;

    $email = $_POST['email'];
    $page = home_url( $wp->request );
        if ( !empty($_POST(interest_1)) && !empty($_POST(interest_2)) ) {
            $interest_1 = true;
            $interest_2 = true;
            insert_interests_to_db ( $email, $page, $interest_1, $interest_2 );
        } elseif ( !empty($_POST(interest_1)) && empty($_POST(interest_2)) ) {
            $interest_1 = true;
            $interest_2 = false;
            insert_interests_to_db ( $email, $page, $interest_1, $interest_2 );
        } elseif ( empty($_POST(interest_1)) && !empty($_POST(interest_2)) ) {
            $interest_1 = false;
            $interest_2 = true;
            insert_interests_to_db ( $email, $page, $interest_1, $interest_2 );
        }
}

And my function for insert data to database:

function insert_interests_to_db ( $email, $page, $interest_1, $interest_2 ) {

    global $wpdb;
    $table_name = $wpdb->prefix . 'interest_types_db';
    $data = array(
        'email' => $email,
        'page' => $page,
        'interest_1' => $interest_1,
        'interest_2' => $interest_2,
    );
    $format = array( '%s', '%s', '%d', '%d' );
    $wpdb->insert( $table_name, $data, $format );

}

I get an error:

Fatal error: Uncaught Error: Function name must be a string...

If I use isset instead of empty:

Cannot use isset() on the result of an expression...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745531573a4631719.html

相关推荐

  • Store comment form custom field in custom database

    I'm trying to add custom field created on comment form to custom database.But my solutions not working. How to chan

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信