评价表开发问题

时间:2020-09-25 作者:Dimitrios Pavlis

我是wordpress主题开发的新手,我正在尝试创建一个自定义的评论表单。我阅读了文档,我对布局感到满意,但我对表单的功能有两个问题。

第一个问题是当我登录wordpress时,我点击;发表评论”;按钮,消息不会保存在MySQL中。我认为在检索用户输入时,我没有正确地执行某些操作。

我的第二个问题是,当我注销时,我有一些字段名称和电子邮件由于某种原因也没有保存,我面临以下错误:Error: Please fill the required fields (name, email).

随函附上我用来创建自定义评论表单的代码。该函数是从single调用的。php文件,这是我创建用来显示单个帖子的文件。

请注意,我请求您的帮助并不是为了帮我解决问题,而是为了了解并确定我做错了什么。原谅我英语不好。我是希腊人!

function dck_custom_comment_form() {
//Declare Vars
$comment_author = \'Name *\';
$comment_email = \'Email *\';
$comment_body = \'Comment *\';
$comment_cookies_1 = \' By commenting you accept the\';
$comment_cookies_2 = \' Privacy Policy\';
$commenter = wp_get_current_commenter();

$fields = array(
    //Author field
    \'author\' => \'<div class="row"><div class="col-md-6"><div class="form-group"><input name="Name" id="name" placeholder="\' . $comment_author .\'" class="form-control" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) . \'"></div></div>\',
    //Email Field
    \'email\' => \'<div class="col-md-6"><div class="form-group"><input name="Email" id="email" placeholder="\' . $comment_email .\'" class="form-control" type="email" value="\' . esc_attr(  $commenter[\'comment_author_email\'] ) . \'"></div></div></div>\',
    //Cookies
    \'cookies\' => \'<div class="col-md-12"><div class="form-group"><input type="checkbox" required>\' . $comment_cookies_1 . \'<a href="\' . get_privacy_policy_url() . \'">\' . $comment_cookies_2 . \'</a></div></div>\',
);

//Array
$comments_args = array(
    \'fields\' => $fields,
    \'comment_field\' => \'<div class="row"><div class="col-md-12"><div class="form-group"><textarea name="message" id="message" placeholder="\' . $comment_body .\'" rows="4" aria-required="true" class="form-control"></textarea></div></div></div>\',
    \'comment_notes_after\' => \'\',
    \'title_reply\' => \'Please Post Your Comments & Reviews\',
    \'label_submit\' => \'Post Comment\'
);
comment_form( $comments_args );}


function dck_reorder_comment_form_fields( $fields ) {
$comment_field = $fields[\'comment\'];
$cookies = $fields[\'cookies\'];
unset( $fields[\'comment\'] );
unset( $fields[\'cookies\'] );
$fields[\'comment\'] = $comment_field;
$fields[\'cookies\'] = $cookies;
return $fields;
}

1 个回复
最合适的回答,由SO网友:Dimitrios Pavlis 整理而成

我解决了这个案子。这里的问题是on&;字段变量声明以及“comment\\u field”赋值。我必须用正确的名称字段更改名称字段。

检查以下代码:

function dck_custom_comment_form() {
   //Declare Vars
   $comment_author = \'Name *\';
   $comment_email = \'Email *\';
   $comment_body = \'Comment *\';
   $comment_cookies_1 = \' By commenting you accept the\';
   $comment_cookies_2 = \' Privacy Policy\';
   $commenter = wp_get_current_commenter();

$fields = array(
    //Author field
    \'author\' => \'<div class="row"><div class="col-md-6"><div class="form-group"><input name="author" id="name" placeholder="\' . $comment_author .\'" class="form-control" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) . \'"></div></div>\',
    //Email Field
    \'email\' => \'<div class="col-md-6"><div class="form-group"><input name="email" id="email" placeholder="\' . $comment_email .\'" class="form-control" type="email" value="\' . esc_attr(  $commenter[\'comment_author_email\'] ) . \'"></div></div></div>\',
    //Cookies
    \'cookies\' => \'<div class="col-md-12"><div class="form-group"><input type="checkbox" required>\' . $comment_cookies_1 . \'<a href="\' . get_privacy_policy_url() . \'">\' . $comment_cookies_2 . \'</a></div></div>\',
);

//Array
$comments_args = array(
    \'fields\' => $fields,
    \'comment_field\' => \'<div class="row"><div class="col-md-12"><div class="form-group"><textarea name="comment" id="message" placeholder="\' . $comment_body .\'" rows="4" aria-required="true" class="form-control"></textarea></div></div></div>\',
    \'comment_notes_after\' => \'\',
    \'title_reply\' => \'Please Post Your Comments & Reviews\',
    \'label_submit\' => \'Post Comment\'
);
comment_form( $comments_args );
  }
谢谢你的努力!

相关推荐