Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9057711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:31:48+00:00 2026-06-16T14:31:48+00:00

I have a very strange problem using CakePHP 2.2.4 , let me explain what

  • 0

I have a very strange problem using CakePHP 2.2.4, let me explain what happen.

I have these mysql tables:

leads

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| user_id    | int(11)      | YES  | MUL | NULL    |                |
| date       | datetime     | YES  |     | NULL    |                |
| ip         | varchar(45)  | YES  |     | NULL    |                |
| service_id | int(11)      | YES  | MUL | NULL    |                |
| location   | varchar(255) | YES  |     | NULL    |                |
| message    | text         | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

users

+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| email   | varchar(200) | YES  |     | NULL    |                |
| pwd     | varchar(200) | YES  |     | NULL    |                |
| role_id | int(11)      | YES  | MUL | NULL    |                |
| active  | tinyint(4)   | YES  |     | 0       |                |
+---------+--------------+------+-----+---------+----------------+

profiles

+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| user_id | int(11)      | YES  | MUL | NULL    |                |
| name    | varchar(120) | YES  |     | NULL    |                |
| surname | varchar(120) | YES  |     | NULL    |                |
| company | varchar(200) | YES  |     | NULL    |                |
| vat     | varchar(60)  | YES  |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+

addresses

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| profile_id | int(11)      | YES  | MUL | NULL    |                |
| address    | varchar(255) | YES  |     | NULL    |                |
| city       | varchar(120) | YES  |     | NULL    |                |
| zip_code   | char(5)      | YES  |     | NULL    |                |
| nation     | varchar(120) | YES  |     | NULL    |                |
| telephone  | varchar(200) | YES  |     | NULL    |                |
| mobile     | varchar(200) | YES  |     | NULL    |                |
| fax        | varchar(200) | YES  |     | NULL    |                |
| email      | varchar(200) | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

roles

+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| name  | varchar(100) | YES  |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+

services

+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| name  | varchar(255) | YES  |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+

and the follow are all the CakePhp Models I use (with the associations):

Lead.php

class Lead extends AppModel {

    public $name = 'Lead';

    /* Relazioni */      
    public $belongsTo = array('User', 'Service');
}

User.php

class User extends AppModel {

    public $name = 'User';

    /* Relazioni */
    public $hasOne = 'Profile';

    public $belongsTo = 'Role';

    public $hasMany = array(
        'Lead' => array(
            'className' => 'Lead'
        )
    );  

}

Profile.php

class Profile extends AppModel {

    public $name = 'Profile';

    /* Relazioni */
    public $belongsTo = 'User';

    public $hasMany = array(
        'Address' => array(
            'className' => 'Address'
        )
    );  

}

Address.php

class Address extends AppModel {

    public $name = 'Address';

    /* Relazioni */        
    public $belongsTo = 'Profile';

}

Service.php

class Service extends AppModel {

    public $name = 'Service';

}

I have a form that must to be saves in more than one mysql table.

This is the code i use to draft the FORM:

<?php

echo $this->Form->create(null, array(
                            'inputDefaults' => array(
                                'error' => false
                            )
                        )
                ); //create(false) per il form senza il modello

echo $this->Form->input('User.Profile.name', array(
                            'label' => array(   
                                'class' => 'name-form',                                                                                                                                         
                                'text'  => 'Nome:'                                                                      
                            ),                                                              
                            'style' => 'width:238px;',
                            'div'   => 'field'
                        )
               );                               

echo $this->Form->input('User.Profile.surname', array(
                            'label' => array(   
                                'class' => 'name-form',                                                                                                                                         
                                'text'  => 'Cognome:'                                                                       
                            ),                                                              
                            'style' => 'width:238px;',
                            'div'   => 'field'
                        )
               );                                   

?>

<div class="clear"></div>

<?php

echo $this->Form->input('User.email', array(
                            'label' => array(                                                                       
                                'class' => 'name-form',
                                'text'  => 'Email:'
                            ),                                                              
                            'div'   => 'field', 
                            'class' => 'input-xlarge'
                        )
               );

echo $this->Form->input('User.Profile.Address.telephone', array(
                            'label' => array(   
                                'class' => 'name-form',                                                                                                                                         
                                'text'  => 'Telefono:'                                                                      
                            ),                                                          
                            'div'   => 'field'
                        )
               );                          
?>

<div class="clear"></div>


<?php                      

echo $this->Form->input('Lead.service_id',
                    array(
                        'label' => array(                                                                       
                            'class' => 'name-form',
                            'text'  => 'Servizio richiesto:'
                        ),                                                              
                        'div'   => 'field',
                        'type'  => 'select',                                                                
                        'options' => $services                                      
                    )
);                              

echo $this->Form->input('Lead.location', array(
                            'label' => array(                                                                       
                                'class' => 'name-form',
                                'text'  => 'Vicino a:'
                            ),                                                              
                            'div'   => 'field', 
                            'class' => 'input-xlarge'
                        )
               );                               

?>

<div class="clear"></div>


<?php

echo $this->Form->input('Lead.message', array(
                            'label' => array(                                                                       
                                'class' => 'message-form',
                                'text'  => 'Richiesta:'
                            ),                                                              
                            'div'   => 'field', 
                            'class' => 'form-field',
                            'type'  => 'textarea'
                        )
               );                                                               

echo $this->Form->button('Invia Richiesta', array(
                                        'type'  => 'submit',
                                        'class' => 'submit-btn less-margin'
                                    )
                );

echo $this->Form->end();

?>

And this is the action of the controller(PagesController) that saves the data:

public function home() 
{       
   if ($this->request->is('post'))
   {
    $this->loadModel('Lead');

    $this->request->data['Lead']['ip']   = $_SERVER['REMOTE_ADDR'];
    $this->request->data['Lead']['date'] = date('Y-m-d H:i:s'); 
    $this->request->data['User']['role_id'] = 3;    

    $this->Lead->set($this->request->data);

    debug($this->request->data);

    if ($this->Lead->validates()) 
    {
        // Dati nel modulo corretti
        debug($this->Lead->saveAll($this->request->data, array('deep' => true)));
    } 
    else 
    {
        // Errore nella validazione
        $this->Session->setFlash('Completare correttamente il form', 'default', array('class' => 'errore'), 'lead');

        $errors = $this->Lead->validationErrors;                
        debug($errors);
    }   
}

$this->loadModel('Service');

$this->set('services', $this->Service->find('list'));               

}

And this is the output generated from the FORM:

array(
    'User' => array(
        'Profile' => array(
            'name' => 'The Name',
            'surname' => 'The Surname',
            'Address' => array(
                'telephone' => 'The Telephone'
            )
        ),
        'email' => 'the@email.com',
        'role_id' => (int) 3
    ),
    'Lead' => array(
        'service_id' => '1',
        'location' => 'The location',
        'message' => 'This is the request',
        'ip' => '127.0.0.1',
        'date' => '2013-01-01 08:07:42'
    )
)

PROBLEM:

All work correctly, except one thing… saveAll() saves all the data correctly (in each model), but in the addresses table I only see that CakePhp insert profile_id, only this field, but as you can see in the array generated from the FORM, I also have the telephone!

Why does cakephp not also insert the telephone field?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:31:50+00:00Added an answer on June 16, 2026 at 2:31 pm

    You are making up code, hence it does not work.

    Nowhere in the cake docs does it say to use the following code:

    Incorrect

    $this->Form->input('User.Profile.surname');
    $this->Form->input('User.Profile.Address.telephone');
    

    You can not just string words together and hope for the best. You can either use:

    Correct

    $this->Form->input('field');
    $this->Form->input('Model.field');
    $this->Form->input('Model.n.field');
    

    There are no other valid ways to enter fields.

    Instead of making things up, read the docs

    $this->Form->input('Profile.surname');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very strange problem with using geometry shaders. I made a very
I have a very strange problem using JQuery. I have a fileupload form where
I'm encountering a very strange problem using g++ 4.1.2. I have a very basic
I have very strange problem with mySQL and simple query with simple index. I
I have a very strange problem. I am using jQuery to intercept a particular
I have a very strange problem while using my ListView. Only a part of
I have a very strange problem. Recently I've created an upload page using jquery
I have a very strange problem. (fyi - I'm using forms authentication and manually
I have a very strange problem when I using ajax in symfony 1.4. I've
I have very strange problem. I'm using IIS 7.0 Integrated mode for my application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.