It's standard practice, whenever you want to edit a record you have to
specify it's id in the data array and it's usually done by adding a
hidden input in your view

On Oct 6, 1:41 pm, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
> That did indeed work. Thank you very much for your help. However I do
> have one more question. I never encountered this being added to views
> in anything that I read about doing data validation. So I am just
> wondering if I am doing something wrong from the get go that makes it
> so that I have to add this, or is this just standard practice?
>
> On Oct 6, 5:30 am, vekija <vedran.konto...@gmail.com> wrote:
>
> > From the book:
> > "One thing to note here: CakePHP will assume that you are editing a
> > model if the 'id' field is present in the data array. If no 'id' is
> > present (look back at our add view), Cake will assume that you are
> > inserting a new model when save() is called."
>
> > So, you'd have to add that hidden field to your view in order this to
> > work, but can leave the code in the controller as is
>
> > On Oct 6, 12:40 pm, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
>
> > > I see what you are saying, I haven't tried this yet. However this
> > > seems very hacky to me with the way most things are done in CakePHP.
> > > Is this really the way I should go about solving this issue?
>
> > > On Oct 6, 3:57 am, vekija <vedran.konto...@gmail.com> wrote:
>
> > > > try removing $this->Message->id = $id; and adding parameters to read
> > > > function at the bottom
>
> > > > $this->data = $this->Message->read(null, $id);
>
> > > > and placing a hidden input file in your form for message id
>
> > > > echo $form->hidden('Message.id');
>
> > > > On Oct 6, 11:22 am, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
>
> > > > > So, my subject name might be misleading. This is why I'm posting on
> > > > > here because I don't have much of an idea of what to search for in
> > > > > order to find a solution.
>
> > > > > So here is my issue. I have a controller with an edit function. The
> > > > > page loads fine, it edits fine, and it invalidates fields fine, and it
> > > > > shows which fields had the error fine. However that's where the
> > > > > problem starts that I noticed. If a user types in data that gets
> > > > > invalidated, and then tries to submit it again, it brings up an error
> > > > > that the $id field is missing from the argument (the url), and it is
> > > > > missing. If the user invalidates some data, corrects the issue, and
> > > > > then clicks submit, the data isn't saved but it says it was saved
> > > > > correctly.
>
> > > > > So my question is, what can I do so that a user can get an invalidated
> > > > > message, but everything will continue working as it is supposed to.
> > > > > Here is my code for the edit function, if you need anything else
> > > > > please just ask.
>
> > > > >                 function edit($id)
> > > > >                 {
> > > > >                         $this->Message->id = $id;
>
> > > > >                         if (!empty($this->data['Message']))
> > > > >                         {
> > > > >                                 $mrClean = new Sanitize();
> > > > >                                 $this->data['Message']['message'] = 
> > > > > $mrClean->clean($this->data
> > > > > ['Message']['message'], array('encode' => 0, 'escape' => 0));
> > > > >                                 $this->data['Message']['modified'] = 
> > > > > date('Y-m-d G:i:s');
>
> > > > >                                 if 
> > > > > ($this->Message->save($this->data['Message']))
> > > > >                                 {
> > > > >                                         $this->Session->setFlash('The 
> > > > > Pastors Message has been edited.');
>
> > > > >                                         $this->redirect('/');
> > > > >                                         $this->exit();
> > > > >                                 }
> > > > >                                 else
> > > > >                                 {
> > > > >                                         $this->Session->setFlash('The 
> > > > > Pastors Message could not be
> > > > > edited.');
> > > > >                                 }
> > > > >                         }
> > > > >                         else
> > > > >                         {
> > > > >                                 $this->data = $this->Message->read();
> > > > >                         }
> > > > >                 }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to