Symfony\Component\Form\FormBuilder::create PHP Method

create() public method

public create ( $name, $type = null, array $options = [] )
$options array
    public function create($name, $type = null, array $options = array())
    {
        if ($this->locked) {
            throw new FormException('The form builder cannot be modified anymore.');
        }

        if (null === $type && null === $this->getDataClass()) {
            $type = 'text';
        }

        if (null !== $type) {
            return $this->factory->createNamedBuilder($name, $type, null, $options, $this);
        }

        return $this->factory->createBuilderForProperty($this->getDataClass(), $name, null, $options, $this);
    }

Usage Example

 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->add('firstname', 'text', array('label' => 'form.label.firstname'))->add('lastname', 'text', array('label' => 'form.label.lastname'))->add('states', 'choice', array('choices' => array('foo' => 'bar'), 'empty_value' => 'form.states.empty_value'))->add('countries', 'choice', array('empty_value' => false))->add('password', 'repeated', array('first_options' => array('label' => 'form.label.password'), 'second_options' => array('label' => 'form.label.password_repeated'), 'invalid_message' => 'form.error.password_mismatch'))->add('street', 'text', array('label' => 'form.label.street', 'translation_domain' => 'address'))->add('zip', 'text', array('label' => 'form.label.zip', 'translation_domain' => 'address'))->add('field_with_placeholder', 'text', array('label' => 'field.with.placeholder', 'attr' => array('placeholder' => 'form.placeholder.text')))->add('field_without_label', 'text', array('label' => false, 'attr' => array('placeholder' => 'form.placeholder.text.but.no.label')));
     $child = $builder->create('created', 'text', array('label' => 'form.label.created'));
     $builder->add('dueDate', 'date', array('empty_value' => array('year' => 'form.dueDate.empty.year', 'month' => 'form.dueDate.empty.month', 'day' => 'form.dueDate.empty.day')));
     $builder->add('field_with_ignored_label', 'text', array('label' => 'form.ignored'));
 }
All Usage Examples Of Symfony\Component\Form\FormBuilder::create