在 Codeigniter 中,如何将第三个参数传递给回调(表单验证)?

发布于 2024-12-25 10:08:20 字数 365 浏览 5 评论 0原文

我目前正在使用表单验证类(在 Codeigniter 上)并设置规则。

它的工作原理与两个参数类似(codeigniter.com/user_guide/libraries/form_validation.html ):

$this->form_validation->set_rules('username', 'Username', 'callback_test[abc]');

但是第三个参数呢?还有第四个……?是否可以?

I am currently using the Form Validation class (on Codeigniter) and setting rules.

It works like this with two parameters (codeigniter.com/user_guide/libraries/form_validation.html):

$this->form_validation->set_rules('username', 'Username', 'callback_test[abc]');

But what about a third parameter? And a fourth...? Is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

旧街凉风 2025-01-01 10:08:20

它不是官方的,但可以用

“,”分割参数

$this->form_validation->set_rules('article_big_image','Gambar Besar','callback_check_picture[article_big_image,edit]');

function check_picture($image,$param){
    $param = preg_split('/,/', $param);
    $field = $param[0];
    $action = $param[1];
    echo $field.$action;
}

It is not official but works

Split the parameter by ','

$this->form_validation->set_rules('article_big_image','Gambar Besar','callback_check_picture[article_big_image,edit]');

function check_picture($image,$param){
    $param = preg_split('/,/', $param);
    $field = $param[0];
    $action = $param[1];
    echo $field.$action;
}
吃兔兔 2025-01-01 10:08:20

并非没有扩展系统表单验证类。有关如何实现此目的的信息,请查看此 文章

或者,您可以使用以下方式访问回调函数中的 post 变量:

$this->input->post('field_name');

这可能会或可能不会帮助您。

Not without extended the system form validation class. For information on how to achieve this take a look at this article.

Alternatively you can access the post variables within your callback function using:

$this->input->post('field_name');

which may or may not help you out.

岛歌少女 2025-01-01 10:08:20

您可以使用数组来获取更多字段的更多参数,如下所示:

 $error = array(

                array(
                'field' => 'check', // the field name will come here
                'label' => 'Check',
                'rules' => 'required|here you can put the callback Function'
                )
          );

You can use Array for more parameters for more fields as like i did below:

 $error = array(

                array(
                'field' => 'check', // the field name will come here
                'label' => 'Check',
                'rules' => 'required|here you can put the callback Function'
                )
          );
她如夕阳 2025-01-01 10:08:20

    $this->form_validation->set_rules('article_big_image','Gambar','callback_check_picture[article_big_image,edit]');
    function check_picture($image,$param){
        $param = explode(',', $param);
        $field = isset($param[0])?$param[0]:'';
        $action = isset($param[1])?$param[1]:'';
       echo $field.$action;
   }

    $this->form_validation->set_rules('article_big_image','Gambar','callback_check_picture[article_big_image,edit]');
    function check_picture($image,$param){
        $param = explode(',', $param);
        $field = isset($param[0])?$param[0]:'';
        $action = isset($param[1])?$param[1]:'';
       echo $field.$action;
   }
酒废 2025-01-01 10:08:20

您可以传递给规则
|callback_handle_is_unique_value_combinations[val1,val2]

比,
公共函数callback_handle_is_unique_value_combinations($str, $field)
{
$fields = 爆炸(',', $field);
$val1 = $fields[0];
$val2 = $fields[1];

然后你就做出了你的 cponarisons

You can pass to the rule
|callback_handle_is_unique_value_combinations[val1,val2]

than,
public function callback_handle_is_unique_value_combinations($str, $field)
{
$fields = explode(',', $field);
$val1 = $fields[0];
$val2 = $fields[1];

and then you made your cponarisons

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文