0
votes

i am developing with cakephp (2.4.7) and i have a problem with a form action link.

I'm having a usersController with edit action.

public function edit($id = null, $slug = null) {
    if (!$id) {
       throw new NotFoundException(__('Invalid User'));
    }
    $user = $this->User->findById($id);
    if (!$user) {
       throw new NotFoundException(__('Invalid User'));
    }
    if ($this->request->is(array('post', 'put'))) {
       // Do stuff here
    }
    // Fill the form
    if (!$this->request->data) {
       $this->request->data = $user;
    }
}

with this code the form ($this->create->('User')); in the edit view get filled correctly. But i have another form in the edit view.

Like:

echo $this->Form->create(null, array(
     'url' => array('controller' => 'useraddresses', 'action' => 'add')
));
echo $this->Form->input('searchvalue');
echo $this->Form->hidden('country');
echo $this->Form->hidden('city');
echo $this->Form->end('save');

When i click the send button from this form, the page links to /useraddresses/add/2 (2 is the id of the user) I have debuged the form with firebug and in the action parameter is also /useraddresses/add/2.

How can i get arround this? I will to send the form to /useraddresses/add without any parameters.

If i delete this piece of code in my edit action, the action link is correctly but my first form does not get filled.

// Fill the form
if (!$this->request->data) {
     $this->request->data = $user;
}
1
// Input fields and Form->end('Send'); ??? paste your input fields code Here - Pratik

1 Answers

0
votes

Use following

if(empty($this->data) )
{
if (!$this->request->data) {
   $this->request->data = $user;
}
}

Instead of ur

if (!$this->request->data) {
   $this->request->data = $user;
}