There are several ways to do this, but I think it is best to use named parameters .
Essentially, in your views /clients/view.ctp, you add client_id to the Contacts / Add link:
$html->link(__('Add contact', true), array('controller' => 'contacts', 'action' => 'add', 'customer_id' => $customer['Customer']['id']));
and in your views / contacts / add.ctp you check the named parameter and use the hidden field:
if (isset($this->params['named']['customer_id'])) { echo $form->input('customer_id', array('type' => 'hidden', 'value' => $this->params['named']['customer_id'])); } else { echo $form->input('customer_id'); }
or select the desired client that is already selected:
echo $form->input('customer_id', array('selected' => @$this->params['named']['customer_id']));
source share