允许用户输入的片段
//fetch user input and pass it in URL
alertify.prompt("Please enter note/remarks for this Form (optional):", function (e,value) {
if (e) {
alertify.success("Form has been submitted");
$.post(SITE_URL+"someController/someAction",$("#frm_submit").serialize()+ "&user_id="+user_id+"&comment="+value, function( data ) {
});
}else{
alertify.error("Your Form is not submitted");
}
});
用户输入:我的项目 Google R&D,面向每个 Google 员工
当表单发布时,输入不完整,如下所示
echo $_POST['comment']
打印 My Project Google R
这里,如果用户在注释中输入特殊字符,例如 &
,则会中断输入
尝试使用 htmlentities($_POST['comment'])
和 htmlspecialchars($_POST['comment'], ENT_QUOTES, 'UTF-8')
但不行工作。
如何允许用户输入特殊字符?
P.S:我没有将此值保存在数据库中
最佳答案
正如 Daan 建议的那样,&
破坏了 javascript 中的 URL。请找到对我有用的更新片段
//fetch user input and pass it in URL
alertify.prompt("Please enter note/remarks for this Form (optional):", function (e,value) {
if (e) {
alertify.success("Form has been submitted");
//encodes special characters in user comment
var comment = encodeURIComponent(value);
$.post(SITE_URL+"someController/someAction",$("#frm_submit").serialize()+ "&user_id="+user_id+"&comment="+comment, function( data ) {
});
}else{
alertify.error("Your Form is not submitted");
}
});
关于javascript - PHP - 显示特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31177180/