检查元素的动态 $ _ POST 验证问题

dynamic $ _ POST validation issue with inspect element

我正在动态验证所有 $_POST 字段。问题是访问者可以使用 Inspect Element 将 name 属性更改为其他任何内容并提交表单,但验证不会发生。例如,如果客户端将名称属性从 email 更改为随机词,则不会对该字段进行验证。我该如何防止这种情况。尽管

我必须动态获取所有 post 字段
<input type = "text" name = "email[0]">
<input type = "text" name = "aphabets[1]">
<input type = "text" name = "numbers[1]">

foreach ($_POST as $key => $value) {
foreach($value as $k => $v){
if ($key[$i] === "email"){
email($v);
}
if ($key[$i] === "numbers"){
required($v);
}
}
}
function email($v){
//validate email
}
function required($v){
//validate email
}

Use 可以使用 jquery、Jquery 验证插件等等..

您不能相信客户端会告诉您验证规则是什么。这包括您发送给客户端并希望原样返回的数据。

也就是说……

visitors can change the name attribute to anything else using Inspect Element and submit the form and the validation will not happen

如果他们将名称更改为您不希望处理的名称,那么处理它就没有任何意义。

have to get all the all the post fields dynamically though

为什么要获取所有字段?

如果字段名称与您期望的模式不匹配,那么除了不知道如何验证它之外,您不知道还能用它做什么。

这不是您编写要请求的表单的字段。你为什么要接受它?

您的系统输入无效。忽略它或将错误返回给浏览器。