English 中文(简体)
特定形式(用户标识)的弃置确认
原标题:Disabling validation for specific form (user login)

The problem

我在每一页(右面)上都有一个标识。 问题是,当用户在登记网页上时,标识表中的田地都经过验证。 页: 1 这两种形式的领域都经过验证。

Ideas:

  • Different field names for registration form (register_username, register_password, register_email) and then set normal names before saving.
  • Different model (but albo using the users table) for login form?

不管怎么说,我只是想知道,解决这一问题的最佳途径是什么。

最佳回答

I m guess 认为两种表格将提交不同的行动,登记表将提交<编码>Users->register()和提交Users->login()的标识。

我建议,在你重新加入<代码>register(>)行动时,你可以尝试将相关变量复制成另一个联系阵列,然后确认和保留,而不是验证和保存<代码>$this->变量。

问题回答

I haven t tried two forms with the same inputs, but this works for two forms with different inputs. I don t see why it shouldn t work for your needs.

View: Make sure each submit button has a name value so that $this->params can identify it.

//first form ...
<?php
    $profile_options = array( label  =>  edit profile ,
                               name  =>  form1 );
    echo $this->Form->end($profile_options);
?>
//second form ...
<?php
    $password_options = array( label  =>  edit password ,
                               name  =>  form2 );
    echo $this->Form->end($password_options);
?>

Controller action: Use $this->params to test for each form submission

if(isset($this->params[ form ][ form1 ])){
    $this->User->set($this->data); //necessary to specify validation rules
       if($this->User->validates(array( fieldList  => array( email )))){
             $this->User->saveField( email , $this->data[ User ][ email ]);
       }
}
elseif(isset($this->params[ form ][ form2 ])){
    //same deal for second form
}

只有在使用你模式中具体规定的一组验证,才能验证你的模型。 例如,你有一个用户模式,首先包括名称、最后名称、电子邮件和密码。 在这种情况下,在创建或编辑用户时,你希望确认所有4项外地规则。 然而,当你们的用户记录能够验证公正的电子邮件和密码规则。 为此,你可以采取一系列办法,具体指明以下领域:

if ($this->User->validates(array( fieldList  => array( email ,  password )))) {
    // valid
} else {
    // invalid
}




相关问题
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> <?...

热门标签