Is it possible to make a custom comment form in WordPress and insert those custom fields of the form in the database?

I tried to make a comment form in WordPress as much as customizable it can be. I’m using SI Captcha plugin with this form. My question is: “It’s possible to make my own form to insert my custom fields with wp_insert_comment, in comment tables of WordPress?”.

I don’t want to use $args and comment_form($args). I want to make my own form. Is it possible?

Read More

My extra fields will be city and captcha.

What I tried till now:

$comment_args = array( 'title_reply'=>'Comentarii', 'comment_notes_before' => '', 'fields' => apply_filters( 'comment_form_default_fields', array( 'author' => '
<div class="comment_left">
  <p class="comment-form-author">'. ( $req ? '<span>*</span>' : '' ) . '
    <input id="author" name="author" placeholder="Nume" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" ' . $aria_req . ' />
  </p>', 'email' => '
  <p class="comment-form-city">' . ( $req ? '<span>*</span>' : '' ) . '
    <input id="email" name="email" placeholder="E-mail" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" ' . $aria_req . ' />'.'</p>', 'city' => '
  <p class="comment-form-email">' . ( $req ? '<span>*</span>' : '' ) . '
    <input id="city" name="city" placeholder="Oras" type="text" value="' . esc_attr(  $commenter['comment_author_city'] ) . '" size="30" ' . $aria_req . ' />'.'</p>
</div>', 'url' => '' ) ), 'comment_field' => '
<div class="comment_right">
  <p>' . '
    <textarea id="comment" name="comment" placeholder="Mesajul tau" cols="45" rows="8" aria-required="true"></textarea>' . '
  </p>
</div>', 'comment_notes_after' => '', 'label_submit'=>__('Scrie o parere') );   comment_form($comment_args);

I also have to say that wp_insert_comment it’s working with a custom form, but how do I add the extra field with add_comment_meta. I tried this next function but is not working:

add_action( 'comment_post', 'save_comment_meta_data', 1 );
function save_comment_meta_data( $comment_id ) {
    add_comment_meta( $comment_id, 'city', $_POST[ 'city' ] );
}

Related posts