Monday, January 17, 2022

[FIXED] in cakephp 3.0 i want to show all modal validation message together

Issue

in cakephp 3.0 i want to show all modal validation message together above the view form. but it is showing with respective input fields. please let me know how i can re position the error message display together above in cake php 3.0.

i am successfully able to hide the error display with input fields in the form by using templates but not able to get modal error messages.

my table class is as below

public function validationDefault(Validator $validator)
{

    $validator
        ->add('id', 'valid', ['rule' => 'numeric'])
        ->allowEmpty('id', 'create');

    $validator
        ->notEmpty('username','Username Must be provided')
        ->add('username', 'validFormat', [
                'rule' => ['custom' , '/^[a-z0-9]{3,}$/i'],
                'message'=>'Username must contain alphnumeric value and must be more that 3 characters']);

    $validator
        ->add('email', 'valid', ['rule' => 'email'])
        ->requirePresence('email', 'create')
        ->notEmpty('email','Email Must be provided');

    $validator
        ->requirePresence('password', 'create')
        ->notEmpty('password','Password must be provided');

   $validator
        ->add('company', 'validFormat', [
                'rule' => ['custom' , '/^[a-z0-9\s,]{3,}$/i'],
                'message'=>'Company name can contain alphanumeric value only']);

    $validator
        ->add('address', 'validFormat',[
                'rule' => ['custom' , '/^[a-z0-9\s,]{3,}$/i'],
                'message'=>'Address must be alphanumeric value.'])
        ->requirePresence('address','create')
        ->notEmpty('address','Address must be provided');  

    $validator
        ->requirePresence('country_id','create')
        ->notEmpty('country_id','Country name must be provided');            

    $validator
        ->add('city', 'valid',['rule' => ['custom' , '/^[a-z0-9\s,]{3,}$/i'],'message'=>'City can containalphanumeric value only.'])
        ->requirePresence('city','create')
        ->notEmpty('city','City must be provided');  

    $validator
        ->add('phone', 'valid',['rule' => ['custom' , '/^[0-9]{10,}$/i'],'message'=>'Phone must be atleast 10 characters.'])
        ->requirePresence('phone','create')
        ->notEmpty('phone','Address must be provided');  


    return $validator;
}

Solution

have you tried to debug the entity? then you would notice the errors. $entity->errors();

try the tutorial: http://book.cakephp.org/3.0/en/tutorials-and-examples.html

You could have googled this yourself



Answered By - Alex Stallen

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.