Search code examples
phpcakephpvalidationcakephp-2.0models

prevent validation from showing on multiple forms cakephp


i have a strange problem, i have a page where in top right there is a login panel,

and somewhere on the middile of the page there is a register form.

Both login form and register form has fields from User Model which username and password.

My problem is when register form submits the validation rules are activated but its shown

both in register form and login form which i dont want.

I want it to work this way, when i submit register form validate only register form and vice versa..

i couldnt find a workaround for this...plz guide me in the right direction.


Solution

  • To show validation errors only in form which is posted and not in other form, you can add check in your view where errors are displayed with the submit button name as in both forms submit buttons will have different names say submit1 and submit2.

    // In Form1
    if(isset($_POST['data']['form1']['submit1']))
    {
     //display validations for form1
    }
    
    // In Form2
    if(isset($_POST['data']['form2']['submit2']))
    {
     //display validations for form2
    }