2015-12-11 44 views
1

我的帖子頁面的邊欄(sidebar-chat.php)中有一個文本區域,其輸入是圖像。點擊此圖片時,評論應該提交。我只是無法弄清楚如何做到這一點。下面是它的外觀和HTML的截圖。我是否應該爲functions.php添加一個函數來實現這個功能?任何建議都會很棒!麻煩搞清楚如何讓我的按鈕提交評論

enter image description here

HTML:

<div class="font-wrap"> 
    <div class="wrapper"> 

    <textarea name="comment" id="comment" class="talk-bubble comment" tabindex="4" placeholder="Enter comment..."></textarea> 

    <p class="sign-in"> 
     Post a new comment 
    </p> 
    <input class="comment-img" type="image" tabindex="5" alt="Submit Comment" value="Submit Comment" src="<?php bloginfo('stylesheet_directory'); ?>/images/sign-in.png" /> 
</div> 
+0

你的表單是否有動作?你在使用AJAX嗎? – slapyo

回答

1

要做到這一點,你需要用表單標籤附上您的輸入和textarea的標籤和設置方法爲 'POST' 如

<form method = "post"> 
     <textarea name="comment" id="comment" class="talk-bubble comment" tabindex="4" placeholder="Enter comment..."></textarea> ` 

    <input type = "submit" class="comment-img" etc/> 
    </form> 

接下來,您可以通過$_POST[]超級全局陣列訪問輸入。

<?php 
    if($_POST['submit']){ 
    $sideBarChat = $_POST['appropriateName']; 
} 
?> 

`

2

你忘了形式的標籤? :)

<div class="font-wrap"> 
    <div class="wrapper"> 
    <form action="action_page.php" method="post"> 

     <textarea name="comment" id="comment" class="talk-bubble comment" tabindex="4" placeholder="Enter comment..."></textarea> 

     <p class="sign-in"> 
     Post a new comment 
     </p> 
     <input class="comment-img" type="image" tabindex="5" alt="Submit Comment" value="Submit Comment" src="<?php bloginfo('stylesheet_directory'); ?>/images/sign-in.png" /> 
    </form> 
    </div> 
</div> 

用您的提交頁面替換action_page.php。您可以在提交頁面上輸入$_POST['comment']的評論輸入。