2016-05-12 93 views
0

我無法弄清楚爲什麼這不會得到textarea的值。我去過大量的stackoverflow帖子,我無法弄清楚什麼是錯的。我嘗試從textfields,從下拉列表等獲得值,他們都工作,我只是不能讓textarea工作。我已經使用_GET,仍然沒有工作。 這是我得到的消息,如果我不使用isset函數:注意:未定義的索引:descri。php無法從文本區域獲取文本

這裏的HTML:

<form role="form" action="saveform.php" method="post" name="eventform"> 
    <div class="form-group"> 
     <label for="descri">Description</label> 
     <textarea name="descri" form="eventform" style="resize:none"></textarea> 
    </div> 

    <button type="submit" class="btn btn-default" id="addform">add</button> 
</form> 

PHP:

<?php 
if(isset($_POST['descri'])) 
    { 
     echo htmlspecialchars($_POST['descri']); 
    } else { 
     echo "DOESNTWORK"; 
} 
?> 
+3

爲什麼你需要form =「eventform」在textarea? – RJParikh

+0

我在添加它的時候,我正在搜索什麼搞亂了,讀了在一些帖子中,我需要補充一點,當我做了一些事情雖然沒有奏效。所以我想我回到了我開始的地方。我認爲這是我的Jquery腳本來檢查textarea的長度,它以某種方式搞亂了它。 –

回答

2

剛剛從文本區域刪除表單屬性:

<textarea name="descri" form="eventform" style="resize:none"></textarea> 
+0

hmm ok,實際上工作並幫助我在真正的代碼中導致問題。雖然我不知道什麼是確切的和如何。我有一個jQuery腳本檢查,以便該值不超過140個字符,該腳本是由於某種原因或其他混亂,所以它傳遞一個空字段到我認爲的PHP腳本。任何想法? –

0

刪除form="eventform" attribut e來自您的<textarea>元素。您不需要設置它,因爲您的<form>將發佈您的數據。從textarea

<form role="form" action="saveform.php" method="post" name="eventform"> 
    <div class="form-group"> 
     <label for="descri">Description</label> 
     <textarea name="descri" style="resize:none"></textarea> 
    </div> 

    <button type="submit" class="btn btn-default" id="addform">add</button> 
</form> 
1

刪除表單屬性,它位於表單中:

<form role="form" action="saveform.php" method="post" name="eventform"> 
    <div class="form-group"> 
     <label for="descri">Description</label> 
     <textarea name="descri" style="resize:none"></textarea> 
    </div> 
    <button type="submit" class="btn btn-default" id="addform">add</button> 
</form> 

你必須使用它,只有當你的textarea的形式之外(還記得形式應該有id不僅僅是name

<form role="form" action="saveform.php" method="post" id="eventform"> 
    <div class="form-group"> 
     <label for="descri">Description</label> 
    </div> 
    <button type="submit" class="btn btn-default" id="addform">add</button> 
</form> 
<textarea name="descri" form="eventform" style="resize:none"></textarea>