Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 表单文本区域isset_Php_Html - Fatal编程技术网

Php 表单文本区域isset

Php 表单文本区域isset,php,html,Php,Html,这是php/html表单文本区域代码 <textarea name="txtDispMsg" cols="1" rows="1" value="<?php if(isset($disp_msg)){echo $disp_msg;} ?>" <?php if(isset($flag) && $flag == 4){echo "div style = 'border:2px solid red;'" . "/div";}?>></texta

这是php/html表单文本区域代码

<textarea name="txtDispMsg" cols="1" rows="1"  value="<?php if(isset($disp_msg)){echo $disp_msg;} ?>" <?php if(isset($flag) && $flag == 4){echo "div style = 'border:2px solid red;'" . "/div";}?>></textarea>

值未在文本区域中使用,请更改

<textarea name="txtDispMsg" cols="1" rows="1"  value="<?php if(isset($disp_msg)){echo $disp_msg;} ?>" <?php if(isset($flag) && $flag == 4){echo "div style = 'border:2px solid red;'" . "/div";}?>></textarea>

值不是HTML语法中Textarea标记的属性。如果要在Textarea中显示内容,必须将内容放在开始和结束Textarea标记之间。您试图通过声明value=“content”来设置内容,但需要执行以下操作:

<textarea name="fieldName" cols="15" rows="4">CONTENT GOES HERE</textarea>
内容在这里
见:


如果您希望在提交时不清除值,则必须在页面顶部处理这些值以查找某些操作,然后在表单中设置这些值

<?php

// check if values submitted to page and if not, set empty value
// add html escaping just in case
$field1 = (isset($_GET['field1'])) ? htmlspecialchars($_GET['field1']) : "";
$field2 = (isset($_GET['field2'])) ? htmlspecialchars($_GET['field2']) : "";
$field3 = (isset($_GET['field3'])) ? htmlspecialchars($_GET['field3']) : "";
$field4 = (isset($_GET['field4'])) ? htmlspecialchars($_GET['field4']) : "";

// toggle radio button if one was selected
$on = ($field4 == "1") ? "checked" : "";
$off = ($field4 == "0") ? "checked" : "";

?>

<html>
<head><title>Test Page</title></head>
<body>
<h1>Test Page</h1>
<form action="test.php" method="GET">
Field 1: <input type="text" name="field1" value="<?php echo $field1; ?>" /><br />
Field 2: <input type="text" name="field2" value="<?php echo $field2; ?>" /><br />
Field 3: <textarea name="field3" cols="15" rows="5"><?php echo $field3; ?></textarea><br />
Field 4: On <input type="radio" name="field4" value="1" <?php echo $on; ?> /> &nbsp; <input type="radio" name="field4" value="0" <?php echo $off; ?> /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>

测试页
测试页

领域1:它不能解决实际问题。。我希望您理解这个问题。我的目标是,如果另一个字段出现错误,用户输入的内容将保留在该字段中,php会告诉用户更正该错误。。但不能清除整个表单,用户必须重新输入所有值。。明白了吗?参见上面的编辑。这完全取决于您将表单提交到何处,但简单的示例是将表单提交回同一页面(假设该页面名为test.php)。检查表单变量,如果它们存在,则使用它们填充PHP变量,否则将它们设置为空字符串。然后用这些变量填充表单值,它们要么是空的,要么不是空的。如果不是空的话,你可以添加逻辑,然后添加红色字体颜色,等等。谢谢迈克。你也可以告诉我,我怎样才能做同样的单选按钮??表示如果用户单击单选按钮,并且在其他地方出现错误,则该单选按钮将保留在那里。我可能会执行与上面相同的操作,但单选的值将为1或0,如果为1,则另一个变量名为$flag=“”或$flag=“checked”。那就永远表现出无忧无虑。还添加了一个示例,说明如何处理编辑后的原始答案中的单选按钮,以便其他人阅读此帖子时从中受益。
<?php

// check if values submitted to page and if not, set empty value
// add html escaping just in case
$field1 = (isset($_GET['field1'])) ? htmlspecialchars($_GET['field1']) : "";
$field2 = (isset($_GET['field2'])) ? htmlspecialchars($_GET['field2']) : "";
$field3 = (isset($_GET['field3'])) ? htmlspecialchars($_GET['field3']) : "";
$field4 = (isset($_GET['field4'])) ? htmlspecialchars($_GET['field4']) : "";

// toggle radio button if one was selected
$on = ($field4 == "1") ? "checked" : "";
$off = ($field4 == "0") ? "checked" : "";

?>

<html>
<head><title>Test Page</title></head>
<body>
<h1>Test Page</h1>
<form action="test.php" method="GET">
Field 1: <input type="text" name="field1" value="<?php echo $field1; ?>" /><br />
Field 2: <input type="text" name="field2" value="<?php echo $field2; ?>" /><br />
Field 3: <textarea name="field3" cols="15" rows="5"><?php echo $field3; ?></textarea><br />
Field 4: On <input type="radio" name="field4" value="1" <?php echo $on; ?> /> &nbsp; <input type="radio" name="field4" value="0" <?php echo $off; ?> /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>