Re: Edit User on second submit
Hi AD7six Ok, that seems to have it working. Thanks for all the replies to get this resolved! Ronan On Tuesday, July 17, 2012 1:27:15 PM UTC+2, AD7six wrote: > > > > On Wednesday, 11 July 2012 15:20:21 UTC+2, 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." >> >> >> 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); >> } >> } >> >> >> >> >> >> Form->create('User', array('action' => 'edit'));?> >> > > If you are using cake 2.x just use > > Form->create('User');?> > > You are forcing the target for the form to /foo/edit instead of taking the > default value (which is the current url). > > AD > -- 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Edit User on second submit
On Wednesday, 11 July 2012 15:20:21 UTC+2, 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." > > > 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); > } > } > > > > > > Form->create('User', array('action' => 'edit'));?> > If you are using cake 2.x just use Form->create('User');?> You are forcing the target for the form to /foo/edit instead of taking the default value (which is the current url). AD -- 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Edit User on second submit
You can also try this code in your edit.cpt file *Form->create('User', array('action' => 'edit/'.$id));?>* where $id is set from the edit() function in controller On Tuesday, July 17, 2012 3:12:25 PM UTC+5:30, Banana Man wrote: > > So when you go to the first edit screen the id is being passed in the URL > from the link: > > Html->link(__('Edit'), array('action' => 'edit', > $user['User']['id'])); ?> : > > but no id is specified when you click the submit link on the edit page. > If i then add a hidden field to the edit page as discussed above it should > pass the id? > > I have also amended my controller as follows: > > > public function edit($id = null) { > *$this->set('id',$id);* > $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); > unset($this->request->data['User']['password']); > } > $this->set('title_for_layout', 'Edit Account'); > } > > > When i try this i just get an error message on the second submit attempt > saying: > > > *Error: *The requested address *'/users/edit'* was not found on this server. > > > So it seems i am passing the id incorrectly on the second edit. Have i > placed the code incorrectly in the controller? > > > Also, how come none of this is mentioned in the Tutorial document? It seems > strange that they would be listing broken code on one of the main tutorials > on the cake site? > > > Thanks, > > Ronan > > > On Tuesday, July 17, 2012 9:06:05 AM UTC+2, Bharat Maheshwari wrote: >> >> >> you have to post a id set from the action >> >> in your controller :- >> >> $this->set('id',$id); >> >> in your view >> >> $this->Form->hidden('id',array('value'=>$id)); >> On Saturday, July 14, 2012 12:21:11 PM UTC+5:30, chuminh wrote: >>> >>> 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." 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); } } Form->create('User', array('action' => 'edit'));?> >>> echo $this->Session->flash(); echo $this->Form
Re: Edit User on second submit
So when you go to the first edit screen the id is being passed in the URL from the link: Html->link(__('Edit'), array('action' => 'edit', $user['User']['id'])); ?> : but no id is specified when you click the submit link on the edit page. If i then add a hidden field to the edit page as discussed above it should pass the id? I have also amended my controller as follows: public function edit($id = null) { *$this->set('id',$id);* $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); unset($this->request->data['User']['password']); } $this->set('title_for_layout', 'Edit Account'); } When i try this i just get an error message on the second submit attempt saying: *Error: *The requested address *'/users/edit'* was not found on this server. So it seems i am passing the id incorrectly on the second edit. Have i placed the code incorrectly in the controller? Also, how come none of this is mentioned in the Tutorial document? It seems strange that they would be listing broken code on one of the main tutorials on the cake site? Thanks, Ronan On Tuesday, July 17, 2012 9:06:05 AM UTC+2, Bharat Maheshwari wrote: > > > you have to post a id set from the action > > in your controller :- > > $this->set('id',$id); > > in your view > > $this->Form->hidden('id',array('value'=>$id)); > On Saturday, July 14, 2012 12:21:11 PM UTC+5:30, chuminh wrote: >> >> 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." >>> >>> >>> 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); >>> } >>> } >>> >>> >>> >>> >>> >>> Form->create('User', array('action' => 'edit'));?> >>> >>> >>> >> 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('addr
Re: Edit User on second submit
you have to post a id set from the action in your controller :- $this->set('id',$id); in your view $this->Form->hidden('id',array('value'=>$id)); On Saturday, July 14, 2012 12:21:11 PM UTC+5:30, chuminh wrote: > > 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." >> >> >> 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); >> } >> } >> >> >> >> >> >> Form->create('User', array('action' => 'edit'));?> >> >> >> > 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')); >> ?> >> >> Form->end(__('Submit'));?> >> >> >> >> >> >> Html->link(__('List Users'), array('action' => >> 'index'));?> >> >> >> >> >> >> 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 >> cake-php+unsubscr...@googlegroups.com 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Edit User on second submit
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." > > > 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); > } > } > > > > > > Form->create('User', array('action' => 'edit'));?> > > >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')); > ?> > > Form->end(__('Submit'));?> > > > > > > Html->link(__('List Users'), array('action' => > 'index'));?> > > > > > > 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 > cake-php+unsubscr...@googlegroups.com 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Edit User on second submit
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." 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); } } Form->create('User', array('action' => 'edit'));?> 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')); ?> Form->end(__('Submit'));?> Html->link(__('List Users'), array('action' => 'index'));?> 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 cake-php+unsubscr...@googlegroups.com 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php