tries to create a form and a confirmation page that asks to confirm whether the user wants to create a connection with the user. The form has a field that accepts the identifier and directs the user to the confirmation page. There are two buttons on the confirmation page, confirmation and rejection, when the user clicks the form confirmation button, it will be sent to the database if the user clicks on it so that the data from the form is discarded. The confirmation page will also print the username of the user they are trying to add.
It seems I can not find the id from the add page (add_admin.ctp).
How can I access the id from the add source page (add_admin.ctp) to use it on the confirmation page (confirm.ctp)?
public function add_admin() { $this->set('title_for_layout', 'Send A Relationship Request'); $this->set('stylesheet_used', 'homestyle'); $this->set('image_used', 'eBOXLogoHome.png'); $this->layout='home_layout'; $account_id=$this->User->find('list', array( 'fields'=>array('account_id'),'conditions' => array( 'id' => $this->Auth->user('id')))); if ($this->request->is('post')) { $this->Relationship->save($this->request->data); if ($this->Relationship->validates(array('fieldList'=>array('receiver_id','Relationship.accountExists')))) { $this->Relationship->save($this->request->data); $this->Session->setFlash('The relationship has been saved'); $this->redirect(array('controller'=>'Relationships', 'action'=>'confirm')); } else { $this->Session->setFlash('The relationship could not be saved. Please, try again.'); } } $this->set('account_id', $account_id); } public function confirm($id){ $this->set('title_for_layout', 'Relationships'); $this->set('stylesheet_used', 'homestyle'); $this->set('image_used', 'eBOXLogoHome.png'); $this->layout='home_layout'; //$id = $this->request->data(`Relationship.receiver_id`); //$id = $this->params('Relationship.id'); $id = $this->params['Relationship']['id']; $compName = $this->request->data(`Account.company_name`); $findName=$this->Account->find('list', array( 'fields'=>array('company_name'),'conditions' => array( 'id' => $id))); debug($id); pr($compName); pr($findName); $this->Relationship->unbindModel(array('hasMany'=>array('Invoice'))); if ($this->request->is('get')) { $this->request->data = $this->Relationship->read(NULL, $id); } else { if ($this->Relationship->save($this->request->data)) { //$this->Session->setFlash('You have successfully confirmed the relationship.'); if($this->request->data['submit'] == "type_1") { $this->Session->setFlash('The relationship has been confirmed'); $this->redirect( array('controller' => 'fields','action' => 'add')); } if($this->request->data['submit'] == "type_2") { $this->Session->setFlash('The relationship was denied'); $this->redirect( array('controller' => 'templates','action' => 'index')); } } else { $this->Session->setFlash('Unable to update your post.'); } } $this->set('compName', $compName); $this->set('findName', $findName); $this->set('id', $id); }
add_admin.ctp
<?php echo $this->Form->create('Relationship', array('action'=>'add_admin')); echo $this->Form->hidden('sender_id',array('label'=>'Enter your eBox ID: ', 'type'=>'text', 'default'=>$account_id)); echo $this->Form->input('receiver_id',array('label'=>'Receiver eBox ID: ', 'type'=>'text')); echo "<br />"; echo $this->Form->end('Submit'); ?>
confirm.ctp
Do you want to create a relationship with <?php echo $findName ?> <?php echo $this->Form->create('Relationship', array('action'=>'confirm')); echo $this->Form->input('id', array('type'=>'hidden')); echo $this->Form->button('Confirm', array('name' => 'submit', 'value' => 'type_1')); echo $this->Form->button('Deny', array('name' => 'submit', 'value' => 'type_2')); ?>