Amit Dangwal
Amit Dangwal

Reputation: 431

how to validate 2 forms on the same page

I want to validate 2 forms in same page, please suggest me the best way an also guide me to validate with the form without using save function(this is jst a demo program)

index.ctp

echo $this->Form->create($temp1);
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->button('Save');
echo $this->Form->end();

echo $this->Form->create($temp2);
echo $this->Form->input('name');
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->button('Save');
echo $this->Form->end();

Controller

public function index(){
               $temp1 = $this->Contact->newEntity($this->request->data);
        if ($this->request->is('post')) {
            $temp1 = $this->Contact->patchEntity($temp1, $this->request->data);
            if($this->Contact->save($temp1))
              {  
}
}
}

Upvotes: 0

Views: 146

Answers (3)

Rahul Dhiman
Rahul Dhiman

Reputation: 29

you can validate through two form with different different id in jquery validation

Upvotes: 0

JohnC
JohnC

Reputation: 177

For validation, go to Model/Table/PostTable.php

  public function validationDefault(Validator $validator){
    $validator
        ->integer('id')
        ->allowEmpty('id', 'create');

    $validator
        ->notEmpty('name');

    $validator
        ->allowEmpty('email');

    $validator
        ->allowEmpty('password');

    return $validator;
}

Upvotes: 0

Disorder
Disorder

Reputation: 430

You can easily validate your forms by using jQuery validation. Check out the link.

Upvotes: 1

Related Questions