When data from a form is posted to the controller the code for
if (empty($this->data))
should not be executed, as $this->data will not be empty.
So I don't understand why this code can interfere with the save()
validation.
On Fri, Sep 18, 2009 at 8:20 AM, Sarah <[email protected]> wrote:
>
> I realized one of the issues, but am still not sure how to solve it.
> I use Model's read method to retrieve the data for the edit, however
> this stops the validation.
> if (empty($this->data)) {
> $this->data = $this->User->read(array
> ('username', 'firstname', 'lastname', 'email', 'animal_id'), $id);
> }
>
> I created a variable to try to limit the loading of data from the
> database into the form, to allow the validations to occur.
> Unfortunately, although this did control when the if statement
> executed, the validations did not appear.
>
> Segments of my code:
> up top I have var $failSave = false;
>
> function admin_edit($id = hnull) {
> if (!$id && empty($this->data)) {
> $this->flash(__('Invalid User', true), array
> ('action'=>'index'));
> }
>
> //if form submitted
> if (!empty($this->data)) {
>
> //if password changed
> //if passwords match
> //include password in list of fields
> to be saved
> $fieldList = ...
> $match = true;
> }
> else {
> $this->flash(__('Passwords do not
> match', true), array('action'=>'index'));
> $match = false;
> }
> }
> //if password not changed, do not include password
> in list of fields to be saved
> else {
> $fieldList = ...
> $match = true;
> }
>
> if ($match && $this->User->save($this->data, true,
> $fieldList)) {
> $this->flash(__('The User has been saved.',
> true), array('action'=>'index'));
> $this->failSave = false;
> } else {
> $this->data['User']['password'] = '';
> $this->data['User']['password'] = '';
> $this->failSave = true;
> }
>
> }
> //load form
> if (!$this->failSave && empty($this->data)) {
> debug($this->failSave);
> $this->data = $this->User->read(array
> ('username', 'firstname', 'lastname', 'email', 'animal_id'), $id);
> }
>
>
> I would appreciate any advice.
>
> Thanks,
> ~Sarah
>
>
> On Sep 17, 10:27 pm, Sarah <[email protected]> wrote:
> > I am not redirecting after an unsuccessful state, I only reset two of
> > the fields to empty strings. The url is the same.
> >
> > Any ideas?
> >
> > Thanks,
> > ~Sarah
> >
> > On Sep 17, 8:29 pm, "Dr. Loboto" <[email protected]> wrote:
> >
> > > Don't do redirect after unsuccessful save, be sure that form URL is
> > > same as your edit action. Presence of data in fields may indicate only
> > > browser forms cache.
> >
> > > On Sep 17, 11:30 am, Sarah <[email protected]> wrote:
> >
> > > > I've searched the forum, and I can't find any posts that correspond
> to
> > > > my question...unfortunately I haven't had much luck with the manual
> > > > either.
> >
> > > > I have user add and edit forms. In my add form the proper validation
> > > > errors show as they supposed to. However, in the edit form the
> errors
> > > > do not show (the page does not validate/save, the page reloads with
> > > > the data still stored in the form fields, but there are no errors
> > > > messages).
> >
> > > > Any idea why the errors show for one but not the other?
> >
> > > > Thanks in advance,
> > > > ~Sarah
> >
> > > > (I understand that you can use FormHelper options to override the
> > > > error message, but this isn't what I want.)
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---