2017-08-30 83 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">