comment form in single post worked well. then after adding some customization, after posting a comment, it redirects to this link wp_comments_post.php with blank page.
Here is my code in comments.php so what is wrong here to make it work again?
<?php
$form_args = array(
'fields' => array(
'author' => ' <form class="getin_form" id="post-a-comment"> <div class="row"> <div class="col-md-6 col-sm-6"> <div class="form-group bottom35"> <input class="form-control" type="text" placeholder="First Name:" required style=" border: none; border-bottom: 1px solid #a5a5a5; border-radius: 0; padding: 12px 0;box-shadow: none;height: 44px;color: #a5a5a5;font-size: 14px;position: relative; "> </div> </div>',
'email' => ' <div class="col-md-6 col-sm-6"> <div class="form-group bottom35"> <input class="form-control" type="text" placeholder="Email:" required id="email" name="email" style=" border: none; border-bottom: 1px solid #a5a5a5; border-radius: 0; padding: 12px 0;box-shadow: none;height: 44px;color: #a5a5a5;font-size: 14px;position: relative; "> </div> </div> ',
),
// change the title of the reply section
'title_reply'=>'Add Comment',
// remove "Text or HTML to be displayed after the set of comment fields"
'comment_notes_after' => '',
// redefine your own textarea (the comment body)
'comment_field' => ' <div class="col-md-12 col-sm-12"> <div class="form-group bottom35"> <p class="comment-form-comment"><div class="form-group"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><br /> <textarea class="form-control" placeholder="Message" style=" border: none; border-bottom: 1px solid #a5a5a5; border-radius: 0; box-shadow: none; " aria-required="true"></textarea></p> </div></div> ',
'submit_field' =>' <div class="col-sm-12" style="padding-right: 0; padding-left: 0;"> <button type="submit" class="button btnprimary form-control"> submit request </button> </div> </div> </form> </div> </div> </div> </div>',
);
comment_form($form_args);
comment form in single post worked well. then after adding some customization, after posting a comment, it redirects to this link wp_comments_post.php with blank page.
Here is my code in comments.php so what is wrong here to make it work again?
<?php
$form_args = array(
'fields' => array(
'author' => ' <form class="getin_form" id="post-a-comment"> <div class="row"> <div class="col-md-6 col-sm-6"> <div class="form-group bottom35"> <input class="form-control" type="text" placeholder="First Name:" required style=" border: none; border-bottom: 1px solid #a5a5a5; border-radius: 0; padding: 12px 0;box-shadow: none;height: 44px;color: #a5a5a5;font-size: 14px;position: relative; "> </div> </div>',
'email' => ' <div class="col-md-6 col-sm-6"> <div class="form-group bottom35"> <input class="form-control" type="text" placeholder="Email:" required id="email" name="email" style=" border: none; border-bottom: 1px solid #a5a5a5; border-radius: 0; padding: 12px 0;box-shadow: none;height: 44px;color: #a5a5a5;font-size: 14px;position: relative; "> </div> </div> ',
),
// change the title of the reply section
'title_reply'=>'Add Comment',
// remove "Text or HTML to be displayed after the set of comment fields"
'comment_notes_after' => '',
// redefine your own textarea (the comment body)
'comment_field' => ' <div class="col-md-12 col-sm-12"> <div class="form-group bottom35"> <p class="comment-form-comment"><div class="form-group"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><br /> <textarea class="form-control" placeholder="Message" style=" border: none; border-bottom: 1px solid #a5a5a5; border-radius: 0; box-shadow: none; " aria-required="true"></textarea></p> </div></div> ',
'submit_field' =>' <div class="col-sm-12" style="padding-right: 0; padding-left: 0;"> <button type="submit" class="button btnprimary form-control"> submit request </button> </div> </div> </form> </div> </div> </div> </div>',
);
comment_form($form_args);
Share
Improve this question
asked Jul 28, 2020 at 4:20
socialsocial
713 silver badges9 bronze badges
1 Answer
Reset to default 0There are other issues in your code or the $form_args
array items, but the main ones are:
The blank page is due to missing hidden comment fields for replying to comments — see
get_comment_id_fields()
, where the fields are in thesubmit_field
arg by default.So to quickly fix that, add
%2$s
in that arg like so:'submit_field' => '... <button type="submit" class="button btnprimary form-control"> submit request </button> %2$s ...',
But you should actually use the
submit_button
arg to customize the submit button HTML, then with thesubmit_field
arg, use something like:'submit_field' => '<div>%1$s %2$s</div>',
The comment
textarea
field needs to have itsname
set tocomment
.'comment_field' => '... <textarea class="form-control" placeholder="Message" ... name="comment"> ...',
Please, make sure your HTML is valid — you've got an unwanted
</form>
tag in thesubmit_field
arg. :(
I hope that helps and please review the comment_form()
reference for details on the other args, and other relevant details/resources.