我能够创建一个textarea框,它将接受文本并将该文本存储到$ _POST超级全局,但是一旦我提交,我就无法将文本“返回”到框中。 (表格是自我提交)。但是,如果我对提交的数据运行简单的回显,它就会显示正常(如下面脚本末尾所示。
$http.get('iata.php').then(function(response){
$scope.originLatLong = response.data;
console.log($scope.originLatLong);
});
使用“<!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
合作的时间。我对任何帮助表示感谢。
答案 0 :(得分:2)
正如Ann Sophie所说,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; ?>
答案 1 :(得分: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
谢谢,顺便说一句,让我尝试替代语法!不那么容易混淆。
答案 2 :(得分:0)
<!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>