Javascript 使用bootstrapValidator验证wordpress评论表单
背景故事 我一直在创建一个基于twitter引导的wordpress主题。我想对表单进行一些前端验证 这将用于评论表单,最终用于联系表单 有用的链接 我要去哪里 我已经让前端验证工作 然而,当我试图提交表单时,什么都没有发生 如果我从functions.php中删除Javascript代码,表单将提交,但不会进行前端表单验证 这是我的代码 Comments.php中的Comments表单 请注意,如果我删除functions.php中的代码,它将提交Javascript 使用bootstrapValidator验证wordpress评论表单,javascript,php,jquery,wordpress,twitter-bootstrap-3,Javascript,Php,Jquery,Wordpress,Twitter Bootstrap 3,背景故事 我一直在创建一个基于twitter引导的wordpress主题。我想对表单进行一些前端验证 这将用于评论表单,最终用于联系表单 有用的链接 我要去哪里 我已经让前端验证工作 然而,当我试图提交表单时,什么都没有发生 如果我从functions.php中删除Javascript代码,表单将提交,但不会进行前端表单验证 这是我的代码 Comments.php中的Comments表单 请注意,如果我删除functions.php中的代码,它将提交 <?php if ('open'
<?php if ('open' == $post->comment_status) : ?>
<div id="respond">
<h3><?php comment_form_title( 'Add a comment', 'Leave a Reply to %s' ); ?></h3>
<div class="cancel-comment-reply">
<small><?php cancel_comment_reply_link(); ?></small>
</div>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>
You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.
</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" class="form-simple">
<?php if ( $user_ID ) : ?>
<p>
Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>.
<a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out »</a>
</p>
<?php else : ?>
<div class="row">
<div class="form-group">
<div class="col-lg-12"><label class="control-label" for="author">Name</label></div>
<div class="col-lg-5"><input class="form-control" name="author" id="author" value="" size="22" tabindex="1" type="text"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-lg-12"><label class="control-label" for="email">Email</label></div>
<div class="col-lg-5"><input class="form-control" name="email" id="email" value="" size="22" tabindex="2" type="text"></div>
<span class="help-block col-lg-12">You're email address will not be published</span>
</div>
</div>
<?php endif; ?>
<!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->
<div class="row">
<div class="form-group">
<div class="col-lg-12"><label class="control-label" for="comment">Comment</label></div>
<div class="col-lg-12"><textarea class="form-control" name="comment" id="comment" cols="100" rows="10" tabindex="3"></textarea></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-lg-12">
<input class="btn btn-primary top-margin bottom-margin comment-btn" name="submit" id="submit" tabindex="4" value="Submit Comment" type="submit" />
</div>
<?php comment_id_fields(); ?>
</div>
</div>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; // If registration required and not logged in ?>
</div>
<?php endif; // if you delete this the sky will fall on your head ?>
你必须要发表评论。
你要提交的表格是否“有效”?是的,当它全部处于绿色状态时,应该可以去。奇怪的是,我真的看不出有什么理由不起作用。也许用输出的HTML和javascript制作一个模拟,看看它是否正在提交。您的控制台中是否有错误?我应该在控制台中查找什么?是的。我真的被为什么什么都不服从弄糊涂了?
function comment_validation_init() {
if(is_single() && comments_open() ) { ?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#commentform').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
author: {
validators: {
notEmpty: {
message: 'Please Enter Your Name'
}
}
},
email: {
validators: {
notEmpty: {
message: 'Please Enter Your Email'
},
emailAddress: {
message: 'This Is Not A Valid Email Address'
}
}
},
comment: {
validators: {
notEmpty: {
message: "Don't Forget To Leave A Comment"
}
}
}
}
});
});
</script>
<?php
}
}
add_action('wp_footer', 'comment_validation_init');