2017-03-27 51 views
0

我能夠創建一個textarea框,它將接受文本並將該文本存儲到$ _POST超級全局文件中,但是一旦提交,我就無法讓文本「回到」框中。 (表格是自我提交的)。如果我運行所提交的數據的簡單的回聲,但是,它顯示正常(如向下面的腳本結束所示。我可以自己提交回textarea盒嗎?

<!DOCTYPE html> <body> <?php require("Connection_to_WS.php"); 
echo ("<form action='Edit_Thread_Description.php' method='post'>"); 

IF (ISSET($_POST['revised_thread_descr'])) { 
$revised_thread_descr=($_POST['revised_thread_descr']); 
ECHO "Edit the Revised_Thread_Description here: <br> <textarea name='revised_thread_descr' rows='5' cols='50' value= $_POST[revised_thread_descr]";  // Fails to return any text on Submit. 
?><p></textarea></p><br><?php 
} 
ELSE {$revised_thread_descr= '[some default]'; 
ECHO "Edit the Revised_Thread_Description here: <br> <textarea name= 'revised_thread_descr' rows='5' cols='50' value= $revised_thread_descr"; 
?><p></textarea></p><br><?php 
} 
ECHO '<br>'; 
echo $_POST['revised_thread_descr']; // Succeeds in returning POST text from the textarea box upon Submit (but outside of the textarea box). 
ECHO '<br>'; 
echo "Click 'Submit': <input type='Submit' name='submit' value='Submit'/>"; 
echo '<br>'; 
mysqli_close($connection); 
?> 
</body> </html> 

在做同樣的事情用「<input type」輕而易舉,但我「已經沉沒小時後得到<textarea合作。我,我會的任何援助表示感謝。

+3

textarea的不使用數值來顯示內容 –

回答

2

正如安·索菲說,有textarea元素 (https://www.w3schools.com/tags/tag_textarea.asp

,如果你上沒有‘值’屬性想要動態追加內容,可以使用:

<?php if (isset($_POST['revised_thread_descr'])): ?> 
<textarea><?= $_POST['revised_thread_descr'] ?></textarea> 
<?php else: ?> 
    // 

注意,您必須呼應它,在我的例子中,我使用的替代語法, (http://php.net/manual/fr/control-structures.alternative-syntax.php) 我認爲是更清潔,當你用PHP + HTML工作

<?= XXX ?>是短期的<?php echo XXX; ?>

+0

感謝您的響應;他們幫助我一起推動。我試圖按照你的建議:IF(ISSET($ _ POST ['revised_thread_descr'])): $ revised_thread_descr =($ _ POST ['revised_thread_descr']); ?>

Revised_thread_descr - 編輯在這裏:


Sebastian

0

我通過上面的'評論'拙劣的迴應。這繼續發表評論:

此代碼的工作原理,但不會重新填充與通過POST超級全球提交給腳本的備註框。

IF(ISSET($_POST['revised_thread_descr'])): 
$revised_thread_descr=($_POST['revised_thread_descr']); ?> 
<p> Revised_thread_descr - Edit here:</p><textarea 
name='revised_thread_descr' rows='5' cols='50' 
<p></textarea></p><br> 
<?php 

ELSE: 
    $revised_thread_descr= '[some default]'; ?> 
<p> Revised_thread_descr - Edit here:</p><textarea name=  'revised_thread_descr' rows='5' cols='50' 
<p></textarea></p><br> 
<?php 
    ENDIF; 

echo "Click 'Submit': <input type='Submit' name='submit' value='Submit'/>"; 
echo '<br>'; 
mysqli_close($connection); 
?> 
</body> 
</html> 

這個代碼,只有一個稍微不同的位置的<p>標籤,吃掉和顯示器關閉</textarea>標籤後到來的所有HTML材料。

IF(ISSET($_POST['revised_thread_descr'])): 
$revised_thread_descr=($_POST['revised_thread_descr']); ?> 
<p> Revised_thread_descr - EDIT HERE:</p><p><textarea name=  'revised_thread_descr' rows='5' cols='50' 
</textarea></p><br> 
<?php 

如瀏覽器渲染的截圖所示。 screenshot of browser rendering of script above

謝謝,順便說一句,讓我試試這種替代語法!減少混淆。

+1

您沒有關閉您的textarea開始標記,它應該是 '' –

0

祝福你!我放棄了,並正在尋求解決方法。我按照你的建議插入了標籤,它一切正常。這是它的要點,一切正常,textarea盒正確填充。非常感謝你的耐心和堅持。告訴我它變得更容易...。 <?PHP //後東西>

<!DOCTYPE html> <body> 
<?php 
echo ("<form action='Textarea_Example.php' method='post'>"); 

// The first IF only executes after the script has run once and created a POST value. On the second run, the first IF executes and successfully populates the textarea box with the latest POSTed value 
IF (ISSET($_POST['revised_thread_descr'])): ?> 
<p>Edit current thread description:<p> 
<textarea name= 'revised_thread_descr' rows='5' cols='50'> 
<?php echo $_POST['revised_thread_descr'] ?> 
</textarea> 

<?php ELSE: 
$revised_thread_descr = 'some default'; ?> 
<p>Edit current thread description:<p> 
<p><textarea name= 'revised_thread_descr' rows='5' cols='50'> 
The textarea box opens with this in it, but only on the first run. Then it successfully switches to the value typed to the textarea box and saved to POST 
</textarea> 
<?php ENDIF; ?> 
</p> 
<?php 
// here's the submit button 
echo "Click 'Submit': <input type='Submit' name='submit' value='Submit'/>"; 
?> 
</body> </html> 
相關問題