Jey Jake,

if the error is with a field that you're not rendering, you wouldn't
see it.
Also, you're not rendering global errors and hidden fields from what I
can see..

Try just printing the entire form ( echo $form; ) and see if you see
where the error lurks, and work backwards from there.

Daniel



On Aug 24, 8:45 pm, Jake Barnes <lkrub...@geocities.com> wrote:
> Here I had a form that tested valid yet would not save to the
> database. Doesn't that seem broken?
>
> I was hand coding a form, so that the HTML/PHP in the template looked
> (in part) like this:
>
>                 <div class="fieldgrp">
>                         <label for="sf_guard_user_profile_school">
>                                 School
>                         </label>
>                         <div class="field">
>                                 <?php echo $form['school']->renderError() ?>
>                                 <select id="UVA-status-registration" 
> class="longfield-select"
> name="sf_guard_user_profile[school]">
>                                         <option><?php echo 
> $form["school"]->getValue() ?></option>
>                                         <option>Architecture</option>
>                                         <option>Arts &nbsp; Sciences</option>
>                                         <option>Business (Darden MBA)</option>
>                                         <option>Engineering</option>
>                                         <option>Law</option>
>                                         <option>Medicine</option>
>                                         <option>Nursing (Curry)</option>
>                                 </select>
>                         </div>
>                 </div>
>                 <div class="fieldgrp">
>                         <label for="sf_guard_user_profile_program">
>                                 Major/Concentration
>                         </label>
>                         <div class="field">
>                                 <?php echo $form['program']->renderError() ?>
>                                 <?php echo $form['program'] ?>
>                         </div>
>                 </div>
>
> Finally, I tried to save the form, and I found that it would not save.
> I got no errors. I switched over to the dev front controller in the
> hopes that I would get an error, but no, I got no error.
>
> My action looked like this:
>
>   public function executeUpdateUser($request)
>   {
>     if ($this->getUser()->getGuardUser())
>     {
>       $this->form = new sfGuardUserProfileForm
> (sfGuardUserProfilePeer::retrieveByPk($this->getUser()->getGuardUser()-
>
> >getProfile()->getId()));
>
>       $submittedValuesArray = $request->getParameter
> ('sf_guard_user_profile');
>       if (is_array($submittedValuesArray)) {
>         $submittedValuesArray["user_id"] = $this->getUser()-
>
> >getGuardUser()->getId();
>
>         $this->form->bind($submittedValuesArray, $request->getFiles
> ('sf_guard_user_profile'));
>         if ($this->form->isValid())
>         {
>           $userProfile = $this->form->save();
>         }
>       }
>
>       $this->getUser()->setFlash('profile_saved', 'Your info is
> updated');
>     }
>   }
>
> After the form->save() line, I tried to echo out data from the saved
> userProfile object:
>
> echo $userProfile->getProgram();
> die();
>
> Sure enough, this showed the correct information on the screen.
> Whatever I had just typed in as my program, that is what was now
> stored in $userProfile.
>
> After awhile of testing, I realized that I'd stupidly left out the id
> of the profile. So, finally, I added this line:
>
>         $submittedValuesArray["id"] = $this->getUser()->getGuardUser()-
>
> >getProfile()->getId();
>
> And now the form saved!
>
> My action now looked like this:
>
>   public function executeUpdateUser($request)
>   {
>     if ($this->getUser()->getGuardUser())
>     {
>       $this->form = new sfGuardUserProfileForm
> (sfGuardUserProfilePeer::retrieveByPk($this->getUser()->getGuardUser()-
>
> >getProfile()->getId()));
>
>       $submittedValuesArray = $request->getParameter
> ('sf_guard_user_profile');
>       if (is_array($submittedValuesArray)) {
>         $submittedValuesArray["id"] = 
> $this->getUser()->getGuardUser()->getProfile()->getId();
>
>         $submittedValuesArray["user_id"] = $this->getUser()-
>
> >getGuardUser()->getId();
>
>         $this->form->bind($submittedValuesArray, $request->getFiles
> ('sf_guard_user_profile'));
>         if ($this->form->isValid())
>         {
>           $userProfile = $this->form->save();
>         }
>       }
>
>       $this->getUser()->setFlash('profile_saved', 'Your info is
> updated');
>     }
>   }
>
> Then I thought, "I guess all the times I tried to save before, without
> an id, I was creating a new record in the database." But I looked in
> the database, and there were no new records. So now I'm thinking that
> id needs to be there in the array of submitted values, even if  it has
> no value, it needs to be there before the form will save it to the
> database. But if this is so, shouldn't there be some kind of error,
> for those situations where there is no id?
>
> Here I had a form that tested valid yet would not save to the
> database. Doesn't that seem broken?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to