0

How could I autopopulate a form that contains entity option things? I'm trying to do an update details form that when called already contains that users information.

I'm using Symphony 2.1.

The form would look like this:

$builder //->add('createdate') //->add('modifydate') ->add('schoolname') ->add('schoolprofile') ->add('streetaddress') ->add('streetaddressext') ->add('country', 'entity', array( 'class' => 'IFS\Account\RegisterSchoolBundle\Entity\Country', 'property' => 'countryname', )) ->add('schoolprogramid', 'entity', array( 'class' => 'IFS\Account\RegisterSchoolBundle\Entity\Schoolprogram', 'property' => 'displayname', )) ->add('schoolsizegroupid', 'entity', array( 'class' => 'IFS\Account\RegisterSchoolBundle\Entity\Schoolsizegroup', 'property' => 'displayname', )) ->add('state', 'entity', array( 'class' => 'IFS\Account\RegisterSchoolBundle\Entity\State', 'property' => 'statename', )) ->add('city', 'entity', array( 'class' => 'IFS\Account\RegisterSchoolBundle\Entity\City', 'property' => 'cityname', )) ; }

Aaron Cole
  • 333
  • 2
  • 11

1 Answers1

0

You can set your default values on the entity level, ex :

class MyObject {

    __construct() {
        $this->setValue('myDefaultValue');
        //...
    }

    //...
}

Also, it seems your question is a duplicate of this one : How to set default value for form field in Symfony2?

Community
  • 1
  • 1
Julien
  • 9,312
  • 10
  • 63
  • 86
  • Ok thanks, Ill look into that. Oh and Im very sorry, I did look but didn't see that question. – Aaron Cole Jan 06 '13 at 09:49
  • I've just searched https://www.google.com/search?q=symfony2+form+default+value&aq=f&oq=symfony2+form+default+value&aqs=chrome.0.59j0j61j0j60l2.13940&sugexp=chrome,mod=2&sourceid=chrome&ie=UTF-8 and it was the first result :-) – Julien Jan 06 '13 at 09:55
  • Haha I know how to use google, but perhaps my problem wasn't explained properly. I need to have the preset content retrieved from the database, before the form is actually built. So, presumably in the entity? Like the second answer on that question you sent me. The problem being I have an entity as one of the form option types so I can't just pass it an answer.. Does that make sense? – Aaron Cole Jan 06 '13 at 10:03