Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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 密码不能是CodeIgniter表单验证中的用户名_Php_Codeigniter - Fatal编程技术网

Php 密码不能是CodeIgniter表单验证中的用户名

Php 密码不能是CodeIgniter表单验证中的用户名,php,codeigniter,Php,Codeigniter,注册时,我希望我的“密码”字段具有以下自定义规则: 不匹配[用户名] 然后,我将设置以下语言: $lang['not_matches'] = "The %s field cannot be the same as the %f field"; (假设%f是字段名) 这可能吗 说清楚一点,我知道如何做不匹配[“$val.”],但我想要一个灵活的规则。我不确定我是否理解你说的话。你想要一个规则,说不匹配['username']作为另一个输入字段的用户名 如果是这样,只需转到system\libra

注册时,我希望我的“密码”字段具有以下自定义规则:

不匹配[用户名]

然后,我将设置以下语言:

$lang['not_matches'] = "The %s field cannot be the same as the %f field";
(假设
%f
是字段名)

这可能吗


说清楚一点,我知道如何做
不匹配[“$val.”]
,但我想要一个灵活的规则。

我不确定我是否理解你说的话。你想要一个规则,说不匹配['username']作为另一个输入字段的用户名


如果是这样,只需转到system\libraries\form_validation.php,然后找到匹配规则并将其复制,将==更改为!==和不匹配的名称。然后转到system\language\english\form\u validation\u lang.php并创建消息。

CI中还没有此类支持。您需要编写自己的回调验证例程

在中有一个例子可以很容易地适应您的需要。

以下是我是如何做到的

application/language/english/form_validation_lang.php application/libraries/MY_Form_validation.php
然后规则就是不匹配[字段名称]

$this->form\u validation->set\u规则('email'、'email'、'required | valid\u email')-%f是此处的第二个参数。如果你想设置一个值,你需要像这样通过,我这样认为。
$this_lang = basename(__DIR__);
require_once("./system/language/$this_lang/form_validation_lang.php");

$lang['not_match'] = "The %s field must not match the %s field.";
class MY_Form_validation extends CI_Form_validation {

  function __construct()
  {
    parent::__construct();
  }

  public function not_match($str, $field)
  {
    if ( ! isset($_POST[$field]))
    {
      return FALSE;
    }

    $field = $_POST[$field];

    return ($str === $field) ? FALSE : TRUE;
  }

}