Codeigniter 2在一个页面上形成validation_errors问题 [英] Codeigniter 2 forms on one page, validation_errors problem

查看:111
本文介绍了Codeigniter 2在一个页面上形成validation_errors问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个网站上,我有一个页面上的2个表单,我有一个问题,与 validation_errors(); 基本上发生了什么,是一个表单我正在检查错误,如果有任何错误,我正在做一些样式将标签转为红色,其他形式只是显示错误使用 echo validation_errors(); 。当我提交的表单不显示错误只是错误样式验证错误显示在窗体中。

On one of my websites I have 2 forms on one page, I am having a problem, with validation_errors(); basically what is happening, is for one of the forms I am checking for errors and if there are any errors I am doing some styling to turn the labels red, how the other form just display errors using echo validation_errors();. When I submit the form that does not display errors just error styling the validation errors are show in the form. How can I stop this?

推荐答案

您的问题有点难读,但如果我理解正确,使用 validation_errors()验证来自一个控制器的2种不同表单的问题,或者处理来自不同表单的错误的问题:其中afaik输出所有错误:

Your question is a bit hard to read, but if I understand correctly - you're having trouble validating 2 separate forms from one controller, or issues dealing with errors from different forms using validation_errors() which afaik prints ALL errors:

在运行验证之前,检查是否存在隐藏字段,表单唯一的字段,或者您可以检查特定提交按钮的值。

Before running validation, check for the existence of either a hidden field, a field that is unique to the form, or you can check the value of the particular submit button.

<form>
<input type="hidden" name="form1" value="whatever">
<input name="form1_email" />
<input type="submit" value="Submit Form 1" />
</form>

然后你可以使用这些方法来检查提交的表单已提交):

Then you can use any of these methods to check which form was submitted (This example checks if "form1" was submitted):

<?php
// Choose one:
if ($this->input->post('form1')): // check the hidden input
if ($this->input->post('form1_email')): // OR check a unique value
if ($this->input->post('submit') == 'Submit Form 1'): // OR check the submit button value

    if ($this->form_validation->run()):

        // process form

    else:
            // Create a variable with errors assigned to form 1
            // Make sure to pass this to your view
            $data['form1_errors'] = validation_errors();
    endif;

endif;
// Do same for form 2

然后在你的视图中, c $ c> validation_errors()您将使用:

Then in your view, instead of using validation_errors() you would use:

if (isset($form1_errors)) echo $form1_errors; // Print only form1's errors

如果这不能帮助我让我知道,发布您的代码。

If this doesn't help let me know, and clarify your question by posting your code.

这篇关于Codeigniter 2在一个页面上形成validation_errors问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆