Skip to content

Instantly share code, notes, and snippets.

@PhazeonPhoenix
Created April 17, 2012 19:29
Show Gist options
  • Save PhazeonPhoenix/2408452 to your computer and use it in GitHub Desktop.
Save PhazeonPhoenix/2408452 to your computer and use it in GitHub Desktop.
Symfony: Objectless Form
<?php
namespace Acme\DemoBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Validator\Constraints as Assert;
class DemoType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name');
$builder->add('email', 'email', array('label' => 'Your Email'));
}
public function getName()
{
return 'demo';
}
public function getDefaultOptions(array $options)
{
$collectionConstraint = new Assert/Collection(array(
'name' => new Assert/MinLength(5),
'email' => new Assert/Email(array('message' => 'Invalid email address')),
));
return array('validation_constraint' => $collectionConstraint);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment