Created
April 8, 2011 09:55
-
-
Save patashnik/909579 to your computer and use it in GitHub Desktop.
Experimental 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 | |
public function someAction() | |
{ | |
$factory = $this->get('form.factory'); | |
$form = $factory->create(new ExperimentalForm(), 'form'); | |
$request = $this->get('request'); | |
if ($request->getMethod() === 'POST') { | |
$form->bindRequest($request); | |
if ($form->isValid()) { | |
return new RedirectResponse($this->generateUrl('homepage')); | |
} | |
} | |
return $this->render('MyBundle:Campaign:test.html.php', array( | |
'form' => $factory->createRenderer($form, 'php'), | |
)); | |
} |
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 My\Company\Form; | |
use Symfony\Component\Form\Type\AbstractType; | |
use Symfony\Component\Form\FormBuilder; | |
class ExperimentalForm extends AbstractType | |
{ | |
public function buildForm(FormBuilder $builder, array $options) | |
{ | |
$builder->add('fields', 'collection', array( | |
'modifiable' => true, | |
'type' => new ExperimentalFormType() | |
)); | |
} | |
} |
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 My\Company\Form; | |
use Symfony\Component\Form\Type\AbstractType; | |
use Symfony\Component\Form\FormBuilder; | |
class ExperimentalFormType extends AbstractType | |
{ | |
public function buildForm(FormBuilder $builder, array $options) | |
{ | |
$builder | |
->add('field', 'text') | |
->add('secondField', 'text'); | |
} | |
public function getDefaultOptions(array $options) | |
{ | |
return array( | |
'data_class' => 'My\Company\Entity\Field' | |
); | |
} | |
} |
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 My\Company\Entity; | |
class Field | |
{ | |
/** | |
* @assert:NotBlank() | |
* @assert:Min(2) | |
*/ | |
private $field; | |
/** | |
* @assert:NotBlank() | |
* @assert:Min(2) | |
*/ | |
private $secondField; | |
public function getField() | |
{ | |
return $this->field; | |
} | |
public function setField($field) | |
{ | |
$this->field = $field; | |
} | |
public function getSecondField() | |
{ | |
return $this->secondField; | |
} | |
public function setSecondField($field) | |
{ | |
$this->secondField = $field; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment