English 中文(简体)
Kohana 3.0 - Validate:如果一个田地没有空洞的话,
原标题:Kohana 3.0 - Validate: Error if one of fields aren t empty

我有四个领域。 请打电话a,b,cd。 我需要加以验证。

错误是指:

  • One til three fields are not empty;

rr:

  • All fields are not empty,
  • All fields are empty;

这里的任何根本解决办法? 得到建议。

<><>Edit>:

仅有的关系是,所有四种变量都以<代码>event_预先确定。 它给我<代码>event_name,event_description.

Edit #2:

现在我有这样的东西......

if (
       !empty($values[ event_date ])
    && !empty($values[ event_time ])
    && !empty($values[ event_name ])
    && !empty($values[ event_description ])
) {

它检查了所有领域都填满,然后,如果确实如此,就会增加活动。

正如我前面说过的那样,当一些外地站装满时,我需要显示方便用户的错误(例如,用户不得不做说明)。 不管怎样,当所有领域都填满时(即所有征兆),或当没有填满任何领域时(这意味着用户忽视增加和不希望增加一)就不应出现任何错误。

如果说的话,我可以写成16部法典,但是没有更好的办法?

最佳回答

这是一种美丽的故事,但只要你对你想要检查的领域具有独特性(如“发明——......”),你就可以通过变数阵列(价值、美元——《开放式守则》等),只检查问题领域。 然后,你可以轻易检查一个或一个局势。

这方面的例子很迅速:

$total = 0;
$filled = 0;
foreach($values as $field => $val) {
    if(strpos($field, event_ ) === 0) {
        $total++;
        if( ! empty($val)) {
            $filled++;
        }
    }
}
if($filled == 0 OR $total == $filled) {
    //PASS VALIDATION
} else {
    //FAIL VALIDATION
}
问题回答

Is there a relationship between one of the entered values and the none entered values?? could you just parse it as an empty value?

if ( ! isset($post->a) )  $post->a =   ;




相关问题
Bind Button.IsEnabled to custom validation with XAML?

I am sorry I didn t know how to title my question any better, you name it if you got a good 1. I have an entity Contact. this person has navigation properties: Address, Phones (A collection of Phone)....

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

Rails 101 | validates_currency?

I ve searched high and low, but I could not find a solution, to what I think seems like a very common task. In a form I want to have a text input that accepts currency strings (i.e. $1,000,000 or ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签