[英]handle disabled javascript user session
I have a registration page that internal users must use to register to use the site. 我有一个注册页面,内部用户必须使用该页面进行注册才能使用该网站。 I'm using javascript to make sure all required field are populated. 我正在使用javascript确保所有必填字段均已填充。
I just ran into an issue where a users browser has javascript diabled. 我只是遇到了用户浏览器禁用了JavaScript的问题。
Now I want to be able to check if the browser has javascript disabled I want to do the check on the server and if a required field is empty I will send a message back to the user to populate that field. 现在,我希望能够检查浏览器是否禁用了javascript,我想在服务器上进行检查,如果必填字段为空,我将向用户发送一条消息,以填充该字段。
Thank you 谢谢
If you want to show validation messages without javascript - you need to validate forms on server (actually, you need to always valdiate forms server-side) and generate different HTML. 如果要显示不带JavaScript的验证消息-您需要在服务器上验证表单(实际上,您始终需要在服务器端验证表单)并生成不同的HTML。
It depends on framework/language you are using to generate HTML. 这取决于您用于生成HTML的框架/语言。
For example in MVC/C# you will be using something like Html.ValidationMessageFor(m => m.whatever) 例如在MVC / C#中,您将使用类似Html.ValidationMessageFor(m => m.whatever)的东西。
You actually should keep them both: javascript (for those who use javascript) to prevent sending wrong data to server. 您实际上应该同时保留它们:javascript(适用于使用javascript的用户),以防止向服务器发送错误的数据。
And then on server you double-check and return modified html 然后在服务器上仔细检查并返回修改后的html
Typically if a user has javascript disabled on their session/browser I will direct them to either enable it before proceeding. 通常,如果用户在其会话/浏览器上禁用了javascript,我将指导他们在继续操作之前启用它。 If your form is not using Ajax or rather is not "reliant" on Ajax then it's possible to formulate a response back to the user. 如果您的表单未使用Ajax或不是在Ajax上“依赖”,则可以将响应表达给用户。
if (is_ajax()) {
//Do your normal processing
} else {
//Validate each input server side, you have to write your own validation here.
$response = array();
if (is_string($_REQUEST['input:name'])) {
} else {
$response['error'] = true;
$response['errorMessage'] = 'Your error message.';
//Handle getting this back to the front end of your registration page.
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.