Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.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_Jquery_Codeigniter_Validation - Fatal编程技术网

Php 有没有办法禁止Codeigniter';什么是内置表单验证?

Php 有没有办法禁止Codeigniter';什么是内置表单验证?,php,jquery,codeigniter,validation,Php,Jquery,Codeigniter,Validation,O具有一个表单,该表单中的字段由jQuery预先填充。当用户单击该字段时,该字段会自动清空,并键入其信息。但是,如果他们没有在每个字段中输入信息,则会提交默认值。我想使用Codeigniter的内置验证来禁止用户创建名为“first name”的帐户 请参见此处:otis.team2648.com/auth/register 谢谢, Blake您可以使用回调函数: //你的规则 $this->form_validation->set_rules('first_name', 'requ

O具有一个表单,该表单中的字段由jQuery预先填充。当用户单击该字段时,该字段会自动清空,并键入其信息。但是,如果他们没有在每个字段中输入信息,则会提交默认值。我想使用Codeigniter的内置验证来禁止用户创建名为“first name”的帐户

请参见此处:otis.team2648.com/auth/register

谢谢,
Blake

您可以使用回调函数:

//你的规则

$this->form_validation->set_rules('first_name', 'required|callback__no_first_name');
//回拨

function _no_first_name($str) {
    if ($str !== 'First Name') {
        return TRUE;
    }
    else
    {
        $this->form_validation->set_message('_no_first_name', 'You should not have "First Name as the first name"');
        return FALSE;
    }
}

不要将默认文本作为值写入字段中!使用此结构:

<input type="text" name="uname" id="uname" placeholder="Your name" />


如果用户将焦点设置在此字段上,文本将消失。但是,如果用户不插入任何内容,则不会提交任何值。

我将扩展表单验证库,并将其转换为一个更有价值的表单验证规则,您可以轻松地重用它

示例-(更改CI版本的相关信息)

将以上代码放入
应用程序/库中的
MY\u Form\u Validation.php

在验证过程中,只需使用如下规则

$this->form_validation->set_rules('first_name', 'required|disallow_string[First Name]');

请注意,您可以对所有字段使用相同的规则,正如我所设想的其他用途一样。

placeholder需要用户支持html5,这绝对不是主流。我认为这更像是一个机会,使一些易于重用的东西,而不是一个单一用途的解决方案。
$this->form_validation->set_rules('first_name', 'required|disallow_string[First Name]');