Created
April 2, 2013 12:01
-
-
Save manuakasam/5291709 to your computer and use it in GitHub Desktop.
Form bound object properties remaining NULL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace NotaryRequest\Controller; | |
| use Zend\Mvc\Controller\AbstractActionController; | |
| use Zend\View\Model\ViewModel; | |
| use NotaryRequest\Entity\Request; | |
| use NotaryRequest\Form\CreateRequestUserForm; | |
| class RequestController extends AbstractActionController | |
| { | |
| public function addAction() | |
| { | |
| $vm = new ViewModel(); | |
| $vm->setTemplate('notary-request/request/add.phtml'); | |
| $sl = $this->getServiceLocator(); | |
| $em = $sl->get('Doctrine\ORM\EntityManager'); | |
| $form = new CreateRequestUserForm($sl); | |
| /** | |
| * @var $httpRequest \Zend\Http\Request | |
| */ | |
| $httpRequest = $this->getRequest(); | |
| $requestEntity = new Request(); | |
| $form->bind($requestEntity); | |
| if ($httpRequest->isPost()) { | |
| $form->setData($httpRequest->getPost()); | |
| if ($form->isValid()) { | |
| \Zend\Debug\Debug::dump($form->getData()); | |
| $em->persist($requestEntity); | |
| $em->flush(); | |
| } | |
| } | |
| return $vm->setVariables(array( | |
| 'form' => $form | |
| )); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @author Manuel Stosic <manuel.stosic@duit.de> | |
| * @copyright 2013 DU-IT GmbH | |
| */ | |
| namespace NotaryRequest\Form; | |
| use DoctrineModule\Stdlib\Hydrator\DoctrineObject; | |
| use NotaryRequest\Entity\Request; | |
| use Zend\Form\Fieldset; | |
| use Zend\InputFilter\InputFilterProviderInterface; | |
| use Zend\ServiceManager\ServiceManager; | |
| class RequestFieldset extends Fieldset implements InputFilterProviderInterface | |
| { | |
| public function __construct(ServiceManager $serviceManager) | |
| { | |
| parent::__construct('request-fieldset'); | |
| $entityManager = $serviceManager->get('Doctrine\ORM\EntityManager'); | |
| $this->setHydrator(new DoctrineObject($entityManager, 'NotaryRequest\Entity\Request')) | |
| ->setObject(new Request()); | |
| $this->add(array( | |
| 'type' => 'Zend\Form\Element\Hidden', | |
| 'name' => 'id' | |
| )); | |
| $notaryFieldset = new NotaryPersonDataFieldset($serviceManager); | |
| $this->add($notaryFieldset); | |
| $contractFieldset = new ContractDataFieldset($serviceManager); | |
| $this->add(array( | |
| 'type' => 'Zend\Form\Element\Collection', | |
| 'name' => 'contracts', | |
| 'options' => array( | |
| 'count' => 1, | |
| 'should_create_template' => false, | |
| 'allow_add' => true, | |
| 'target_element' => $contractFieldset | |
| ) | |
| )); | |
| $this->add(array( | |
| 'type' => 'Zend\Form\Element\Select', | |
| 'name' => 'criteria', | |
| 'options' => array( | |
| 'label' => 'Ausschlusskriterium laut BauBG?', | |
| 'empty_option' => 'Bitte zutreffendes auswählen', | |
| 'value_options' => array( | |
| Request::CRITERIA_NONE => 'Nein, nichts zutreffend', | |
| Request::CRITERIA_P24A2BAUBG_HERITATE => '§ 24 Abs. 2 BauGB - Erbbaurecht', | |
| Request::CRITERIA_P24A2BAUBG_OWNERSHIP => '§ 24 Abs. 2 BauGB - Wohnungseigentum', | |
| Request::CRITERIA_P26A1Z1BAUBG_FAMILY => '§ 26 Abs. 1 Ziffer 1 BauGB - Verwandschaftsverhältnis', | |
| Request::CRITERIA_P26A1Z2BAUBG_PUBLIC_OR_RELIGION => '§ 26 Abs. 1 Ziffer 2 BauGB - öffentliche oder religiöse Zwecke' | |
| ) | |
| ), | |
| 'attributes' => array( | |
| 'required' => true, | |
| ) | |
| )); | |
| $salesFieldset = new SalesPersonDataFieldset($serviceManager); | |
| $this->add($salesFieldset); | |
| $acquirerFieldset = new AcquirerPersonDataFieldset($serviceManager); | |
| $this->add($acquirerFieldset); | |
| $estateFieldset = new EstateFieldset($serviceManager); | |
| $this->add(array( | |
| 'type' => 'Zend\Form\Element\Collection', | |
| 'name' => 'estates', | |
| 'options' => array( | |
| 'count' => 1, | |
| 'should_create_template' => false, | |
| 'allow_add' => true, | |
| 'target_element' => $estateFieldset | |
| ) | |
| )); | |
| } | |
| /** | |
| * Should return an array specification compatible with | |
| * {@link Zend\InputFilter\Factory::createInputFilter()}. | |
| * | |
| * @return array | |
| */ | |
| public function getInputFilterSpecification() | |
| { | |
| return array( | |
| 'criteria' => array( | |
| 'required' => true | |
| ) | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @author Manuel Stosic <manuel.stosic@duit.de> | |
| * @copyright 2013 DU-IT GmbH | |
| */ | |
| namespace NotaryRequest\Form; | |
| use DoctrineModule\Stdlib\Hydrator\DoctrineObject; | |
| use Zend\Form\Form; | |
| use Zend\ServiceManager\ServiceManager; | |
| class CreateRequestUserForm extends Form | |
| { | |
| public function __construct(ServiceManager $serviceManager) | |
| { | |
| parent::__construct('create-request-user-form'); | |
| $entityManager = $serviceManager->get('Doctrine\ORM\EntityManager'); | |
| $this->setHydrator(new DoctrineObject($entityManager, 'NotaryRequest\Entity\Request')); | |
| $requestFieldset = new RequestFieldset($serviceManager); | |
| $requestFieldset->useAsBaseFieldset(true); | |
| $this->add($requestFieldset); | |
| $this->add(array( | |
| 'type' => 'Zend\Form\Element\Csrf', | |
| 'name' => 'duitsecutiry' | |
| )); | |
| $this->add(array( | |
| 'type' => 'Zend\Form\Element\Submit', | |
| 'name' => 'createRequestSubmit', | |
| 'attributes' => array( | |
| 'id' => 'formsubmit', | |
| 'value' => 'Antrag einreichen', | |
| 'class' => 'btn btn-large btn-success' | |
| ) | |
| )); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment