Tuesday, May 14, 2013

Form validation multiple model errors

Hi,

Got a client update form with a lot of client data split over 2 DB tables (so 2 CakePHP models).

My form named 'Client' have fields like:

                                  <div class="control-group">
                                    <label class="control-label">Bedrijfsnaam <span style="color: red;">*</span></label>
                                    <div class="controls">
                                      <?php echo $this->Form->input('UserData.companyname', array('label' => false, 'error' => array('wrap' => 'div', 'class' => 'error'))); ?>
                                    </div>
                                  </div>                                   
                                      
                                  <div class="control-group">
                                    <label class="control-label">Straatnaam <span style="color: red;">*</span></label>
                                    <div class="controls">
                                      <?php echo $this->Form->input('UserData.company_street', array('label' => false, 'error' => array('wrap' => 'div', 'class' => 'error'))); ?>
                                    </div>
                                  </div>

                                  <div class="control-group">
                                    <label class="control-label">Gebruikersnaam</label>
                                    <div class="controls">
                                      <?php echo $this->Form->input('Client.username',  array('label' => false, 'error' => array('wrap' => 'div', 'class' => 'error'))); ?>
                                    </div>
                                  </div>

In my Client controller i validate the data this way:
                $this->Client->set( $this->data['Client'] );
                $this->Clientdata->set( $this->data['UserData'] );

if($this->Clientdata->validates() && $this->Client->validates()) {


The problem: my validation errors don't show up in my update form. My validation fails because i get results when i print the errors with:
print_r($this->Client->invalidFields()); and print_r($this->Clientdata->invalidFields());

Anybody know what is wrong here? Has it to do with my input form names?

I'm curious!

Raymond

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: