2017-08-30 85 views
0

我在我的页面中的注释部分。需要插入并刷新页面的提交按钮

<form class="reply-form" id="reply-form" method="POST"> 
     <input type="hidden" name="id" value="<?php echo $post->ID;?>" id="postid"> 
      <div class="row"> 
       <div class="col-md-6"> 
        <div class="form-group"> 
         <label class="sr-only control-label" for="name"></label> 
         <input id="name" name="name" class="form-control" placeholder="NAME" required="" type="text"> 
        </div> 
       </div> 
       <div class="col-md-6"> 
        <div class="form-group"> 
         <label class="sr-only control-label" for="email"></label> 
         <input id="email" name="email" class="form-control" placeholder="E-MAIL" required="" type="text" > 
        </div> 
       </div> 
       <div class="form-group"> 
        <div class="col-md-12 mb30"> 
         <label class="sr-only control-label" for="textarea"></label> 
         <textarea class="form-control" id="textarea" name="textarea" rows="3" placeholder="COMMENT"></textarea> 
        </div> 
       </div> 
       <div class="col-md-12"> 
        <div class="form-group"> 
         <button id="singlebutton" name="singlebutton" value="Submit" class="btn btn-default sub">Submit</button> 
        </div> 

       </div> 
      </div> 

     </form> 

这是我插入注释功能是如何工作的:

if(isset($_POST['singlebutton'])){ 
$postid = $_POST["id"]; 
$name =$_POST['name']; 
$email =$_POST['email']; 
$comment=$_POST['textarea']; 

$commentdata = array(
    'comment_post_ID' => $postid, 
    'comment_author' => $name, 
    'comment_author_email' => $email, 
    'comment_content' => $comment, 
    'comment_type' => '', 
    'comment_parent' => 0, 
    'user_id' => $current_user->ID, //passing current user ID or any predefined as per the demand 
); 


$comment_id = wp_new_comment($commentdata); 
} 

现在我的问题是,当我点击提交按钮,它刷新页面,只有插入数据库,只有在下次刷新注释的评论正在mu页面中显示。我已经尝试过使用脚本进行窗口加载,但是这似乎在做这项工作。我能做什么 ?

+0

表单中的认沽行动,如果插件是另一个页面到<形式类=“回复形式” ID =“回复形式”行动=“insert.php”方法=“POST”> –

回答

0

<form class="reply-form" id="reply-form" method="POST" action="yourclassname.php">

添加动作像上面提到.....

0

提交代码重定向页面后本身。

在PHP

header('Location: redirectpage.php');exit(); 

在Javascript中

echo "<script>location.href='redirectpage.php';</script>"; 
0

//只是改变名称于uname所以“名”是不可用的字段名。

<input id="name" name="name" class="form-control" placeholder="NAME" required="" type="text"> 

<input id="name" name="uname" class="form-control" placeholder="NAME" required="" type="text">