Remember, the submitted values from the form are bound to the form, and then
the values are passed to fromArray() on your Doctrine object. If you've used
fromArray() before it is not a magic way to always update your object from
an array of data. It isn't magically able to accept any form data and know
what to do with it in your object. In your case you will need to do some
manual work to update your object properly from the form->getValues().
- Jon
On Fri, Oct 31, 2008 at 2:39 PM, isleshocky77 <[EMAIL PROTECTED]>wrote:
>
> With 1.2 around the corner I'm taking my first crack at the new form
> system brought by the 1.1 release. I need to make a form which is
> essentially made up of a bunch of inner forms.
>
> I'll post my schema at the bottom. Basically I have a table of
> Skills, just consist of a name, description and group the skill
> belongs to. Then I have a table named SkillReport which is just a
> name and descrtiption, and finally a table named SkillPerson which
> combines a skill_id, skill_report_id, sf_guard_user_id, and rating.
> Basically ties everything together to keep track of a skill for a
> given person in that report.
>
> So I need to make a form which contains many SkillPerson's after going
> around in circles of trying to make a single form object with a
> skill_person[rating][0] where 0 is the skill_id, I stumbled upon
> embedForm. Using this
> I'm able to make my own form which embed multiple SkillPeron forms.
> {{{
> #!php
> $Skills = Doctrine::getTable('Skill')->findAll();
> foreach ( $Skills as $Skill ) {
> $SkillPerson = new SkillPerson();
> $SkillPerson['skill_report_id'] = 1;
> $SkillPerson['sf_guard_user_id'] = 2;
> $SkillPerson['skill_id'] = $Skill['id'];
> $this->embedForm("rating[{$Skill['id']}]", new
> SkillPersonForm($SkillPerson));
> }
> }}}
> It displays correctly but I'm having a hard time with the bind
> function in my action and validation. Validation is all over the
> place.
>
> It would be greatly helpful if someone could post an example of using
> the embedForm functionality as well as validating it and using it's
> values. Below is the schema.yml, the SkillFillOutReportForm.class.php
> (my custom form), and SkillPersonForm.clas.php (the modified generated
> form, and my action.
>
> Thanks for any help in advance.
>
> {{{
> #yml
> #schema.yml
> SkillGroup:
> columns:
> name: string
> description: string
>
> Skill:
> columns:
> skill_group_id: integer
> name: string
> description: string
> relations:
> Group:
> class: SkillGroup
>
> SkillReport:
> columns:
> name: string
> description: string
> date: timestamp
> deadline: timestamp
>
> SkillPerson:
> columns:
> skill_id: integer
> sf_guard_user_id: integer(4)
> skill_report_id: integer
> rating: integer(2)
> relations:
> User:
> class: sfGuardUser
> Skill:
> class: Skill
> Report:
> class: SkillReport
> }}}
>
> {{{
> #!php
> // SkillFillOutReportForm.class.php
> class SkillFillOutReportForm extends sfForm
> {
> public function setup()
> {
> $Skills = Doctrine::getTable('Skill')->findAll();
> foreach ( $Skills as $Skill ) {
> $SkillPerson = new SkillPerson();
> $SkillPerson['skill_report_id'] = 1;
> $SkillPerson['sf_guard_user_id'] = 2;
> $SkillPerson['skill_id'] = $Skill['id'];
> $this->embedForm("rating[{$Skill['id']}]", new
> SkillPersonForm($SkillPerson));
> }
> $this->widgetSchema->setNameFormat('skill_person[%s]');
> $this->errorSchema = new sfValidatorErrorSchema($this-
> >validatorSchema);
> parent::setup();
> }
> }
> }}}
>
> {{{
> #!php
> // SkillPersonForm.class.php
> class SkillPersonForm extends BaseSkillPersonForm
> {
> public function configure()
> {
> unset($this['created_at'], $this['updated_at'], $this['slug']);
> $this->setWidgets(array(
> 'sf_guard_user_id' => new sfWidgetFormInputHidden(),
> 'skill_report_id' => new sfWidgetFormInputHidden(),
> 'rating' => new sfWidgetFormChoice(array(
> 'choices' => SkillPersonTable::getRatingChoices(),
> 'expanded' => true))
> ));
> $this->setValidators(array(
> 'sf_guard_user_id' => new
> sfValidatorDoctrineChoice(array('model' => 'sfGuardUser', 'required'
> => true)),
> 'skill_report_id' => new
> sfValidatorDoctrineChoice(array('model' => 'SkillReport', 'required'
> => true)),
> 'rating' => new sfValidatorChoice(array('choices' =>
> array_keys(SkillPersonTable::getRatingChoices()))),
> ));
> }
> }
> }}}
>
> {{{
> #!php
> //actions.class.php
> public function executeFillOut($request)
> {
> $this->form = new SkillFillOutReportForm();
> if ($request->isMethod('post'))
> {
> $this->form->bind($request->getParameter('skill_person'));
> if ($this->form->isValid())
> {
> $values = $this->form->getValues();
> }
> }
> }
> }}}
> >
>
--
Jonathan H. Wage
Open Source Software Developer & Evangelist
http://www.jwage.com
http://www.doctrine-project.org
http://www.symfony-project.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" 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/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---