G
G
Genri_Rus2020-05-30 18:46:57
WordPress
Genri_Rus, 2020-05-30 18:46:57

How to add the ability to upload photos to the comment form?

Here is an example: vintagetechnics.ru/comment

Created an input with a file type for the given field:

$defaults = [
    'fields'               => [
      'name' => '<dd class="-inline-group comment-form__header">
        <input class="-col-12" type="text" name="name" id="name" value="" placeholder="Представьтесь" maxlength="40" data-charcounter="no">
      </dd>',
      'file' => '<dd><input type="file" name="comment_image_"' . $post->ID .'" id="comment_image"></dd>'
      'email'  => '',
      'url'    => '',
      'cookies' => '',        
    ],
    'comment_field'        => '<dd>
      <textarea class="-col-12" name="commenttext" id="commenttext" placeholder="Комментарий" rows="5" maxlength="3000" data-charcounter="no" cols="80"></textarea>
    </dd>',
    'must_log_in'          => '<p class="must-log-in">' . 
      sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '
     </p>',
    'logged_in_as'         => '',
    'comment_notes_before' => '',
    'comment_notes_after'  => '',
    'id_form'              => 'comment_form',
    'id_submit'            => 'submit',
    'class_form'           => 'new-item',
    'class_submit'         => 'submit',
    'name_submit'          => 'submit',
    'title_reply'          => '',
    'title_reply_to'       => __( 'Leave a Reply to %s' ),
    'title_reply_before'   => '',
    'title_reply_after'    => '',
    'cancel_reply_before'  => '',
    'cancel_reply_after'   => '',
    'cancel_reply_link'    => __( 'Cancel reply' ),
    'label_submit'         => 'Отправить',
    'submit_button'        => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
    'submit_field'         => '<p class="form-submit">%1$s %2$s</p>',
    'format'               => 'xhtml',
  ];

comment_form( $defaults );


But how now, when adding a photo, save it and display it in a comment?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question