I am having the same problem with edit. I got exactly the same code as
above. but when I try to edit and save the data, it does not save, it gives
me flash message. I wonder what is wrong with the code because i follow
this edit function from blog tutorial.
Thanks
On Wednesday, July 11, 2012 11:47:44 PM UTC+10, Max Dörfler wrote:
>
> I guess in your view you have to pass in the id (echo
> $this->Form->input('id');). This should include a hidden id field.
> I wonder why it works the first time (without leaving a field blank). Are
> you sure the user gets edited and not a new user created? Because when you
> save $this->request->data, the data shouldn't contain the id if you didn't
> pass it from the view!
>
> On 07/11/2012 03:20 PM, Banana Man wrote:
>
> Hi,
>
> I am trying to setup an Edit User authentication action. I have
> authentication working fine for adding a user but when i try to edit a user
> i am running into a problem.
>
> If i try to edit a user when all information supplied passes validation
> it works fine (URL: http://localhost/users/edit/3). If however i leave a
> textfield blank when i am validating it against 'notEmpty' the first time i
> hit the form submit button it works as expected and reloads the edit user
> page with the validation error displayed (URL:
> http://localhost/users/edit/3). If i do nothing and try to submit the
> form again with the blank textfield i now get redirected to
> http://localhost/users/edit with an Invalid User message "*Error: * The
> requested address *'/users/edit'* was not found on this server."
>
> <!-- app/Controller/UsersController.php -->
> public function edit($id = null) {
> $this->User->id = $id;
> if (!$this->User->exists()) {
> throw new NotFoundException(__('Invalid user'));
> }
> if ($this->request->is('post') || $this->request->is('put')) {
> if ($this->User->save($this->request->data)) {
> $this->Session->setFlash(__('The user has been saved'));
> $this->redirect(array('action' => 'index'));
> } else {
> $this->Session->setFlash(__('The user could not be saved.
> Please, try again.'));
> }
> } else {
> $this->request->data = $this->User->read(null, $id);
> }
> }
>
>
>
> <!-- view/users/edit.ctp -->
> <div class="users form">
> <?php echo $this->Form->create('User', array('action' => 'edit'));?>
> <fieldset>
> <legend><?php echo __('Edit User'); ?></legend>
> <?php
> echo $this->Session->flash();
> echo $this->Form->input('firstname', array('label' => 'First Name'));
> echo $this->Form->input('secondname', array('label' => 'Second Name'));
> echo $this->Form->input('address_01', array('label' => 'Address Line
> 1'));
> echo $this->Form->input('address_02', array('label' => 'Address Line
> 2'));
> echo $this->Form->input('address_03', array('label' => 'Address Line
> 3'));
> echo $this->Form->input('address_04', array('label' => 'Address Line
> 4'));
> echo $this->Form->input('tel_01', array('label' => 'Telephone'));
> echo $this->Form->input('email');
> echo $this->Form->hidden('role', array('value' => 'customer'));
> ?>
> </fieldset>
> <?php echo $this->Form->end(__('Submit'));?>
> </div>
> <div class="actions">
> <h5><?php echo __('Actions'); ?></h5>
> <ul>
>
> <li><?php echo $this->Html->link(__('List Users'), array('action' =>
> 'index'));?></li>
> </ul>
> </div>
>
>
>
> Does anyone know why i am getting redirected on the second submit?
>
> Thanks!
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group
> at http://groups.google.com/group/cake-php
>
>
>
>
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php