i post data into form action to PHP self一些字符出错。这个字符是"
或'
,如果你把"
输入名称返回到'
如何修复
<form id="form1" name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<label for="name"></label>
<input name="name" type="text" id="name" value='<? print htmlspecialchars($_POST['name']); ?>' />
<br />
<input type="submit" name="button" id="button" value="Submit" />
<? print htmlspecialchars($_POST['name']); ?>
</form>
我不太确定问题是什么,但我认为你在输入字段中返回特殊字符时会出错。如果是这样,试试这个:http://php.net/manual/en/function.htmlentities.php你需要将特殊字符转换成html实体,这样数据就不会被当作代码读取,这会导致问题。我刚刚通过将message
input
更改为<?php echo htmlentities($_POST['name']); ?>
进行了测试,字符显示正常。使用以下代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="name"></label>
<input name="name" type="text" id="name" value="<?php echo htmlentities($_POST['name']); ?>" />
<br />
<label for="message"></label>
<textarea name="message" id="message" cols="45" rows="5"><?php echo $message; ?></textarea>
<br />
<input type="submit" name="button" id="button" value="Submit" />
</form>
echoed (<?php echo htmlentities($_POST['name']); ?>);
</body>
</html>