trying to create a form and a confirmation page which asks to confirm if the user wants to create a relationship with a user. The form just has a field which takes an id and directs the user to the confirm page. The confirmation page has two buttons, confirm and deny when a user clicks confirm the form will be submitted to the database, if they user clicks deny the data from the form will be discarded. The confirmation page also will print the username of the user they are trying to add.
I cant seem to retrieve the id from the add page (add_admin.ctp).
How would I access the id from the original add page (add_admin.ctp) to use it in the confirm 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'));
?>
Add the ID to the redirect:
To become something like: