2016-01-06 61 views
1

我有以下代碼。這在我的管理面板上用於管理員將其筆記放入其他管理員可以讀取它。我不想將它存儲在數據庫中。窗體不保存到PHP文件

問題是表單沒有保存文本在textarea中。

<?php 
IF (ISSET($_POST["submit"])) { 
$string = '<?php 
$notes = "'. $_POST["notes"]. '"; 
?>'; 

$fp = FOPEN("includes/notes.php", "w"); 
FWRITE($fp, $string); 
FCLOSE($fp); 
echo '<div class="ok">' . $lang["done"] . '</div>'; 
} 

include("includes/notes.php"); 
?> 
<form action="" method="post" id="notesform"> 
<textarea placeholder="Admin notes" class="notes" id="notes"><?php echo $notes; ?></textarea> 
<input type="submit" value="OK"> 
</form> 

什麼問題?我怎樣才能解決這個問題?我曾在Google上嘗試過大部分建議,但它一直在發生!

+0

更改''轉到''那麼你先IF測試實際上會在'$ _POST'中找到按鈕名稱。 – RiggsFolly

+0

順便說一句:在camelcase中編寫函數等是很可怕的。難以閱讀的其他開發人員可以加入你的團隊等。想想看。 –

+1

@bub你的意思是大寫.. camelCase就好.. –

回答

3

您沒有給name屬性提交按鈕。

當我們向PHP提交表單時,只有元素獲得name屬性。

所以,你的代碼是不是進入:

IF (ISSET($_POST["submit"])) { // Not satisfying this condition. 

更正代碼:

<input type="submit" value="OK" name="submit"> 

申請文本區域也同樣如此。

+0

Ooooh當然!我試圖在'form'標籤之前加入,但那不起作用。謝謝你的幫助! –

+0

@Pupil,是否可以在這裏獲得文本區域值而不給出name =「notes」? –

+0

是的,@AmitRajput,你是對的。我會糾正我的答案。謝謝你的收穫。 – Pupil

2

您沒有給文本區域提供name =「notes」並提交按鈕名稱。這是完整正確的代碼。試試這個:

<?php 
IF (ISSET($_POST["submit"])) { 
$string = $_POST["notes"]; 

$fp = FOPEN("includes/notes.php", "w"); 
FWRITE($fp, $string); 
FCLOSE($fp); 
echo '<div class="ok">' . $lang["done"] . '</div>'; 
} 

include("includes/notes.php"); 
?> 
<form action="" method="post" id="notesform"> 
<textarea placeholder="Admin notes" class="notes" name="notes" id="notes"><?php echo $notes; ?></textarea> 
<input type="submit" name="submit" value="OK"> 
</form> 
+0

@john是否適合你? –

+0

是的,我現在正在工作,你上面的那個人快一點。不過,感謝您的幫助。非常感謝 –

+0

謝謝......乾杯! :-) –