Y
Y
yuklia_12015-03-16 12:35:10
symfony
yuklia_1, 2015-03-16 12:35:10

How to create symfony form in standalone case using form component?

Есть класс формы

class SignInForm extends AbstractType
{
    public function 
buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('login')
            ->add('password')
            ->add('save', 'submit');
    }

    public function getName()
    {
        return 'signin';
    }
}

как его привязать к entity и отправить на рендер?

что-то вроде 
 $form = $formFactory->create(new SignupForm(), $user);
 $view->form = $form->createView();

P/S I'm interested in creating the form directly in the class not via $formFactory->createBuilder()->getForm()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pavlov, 2015-03-16
@yuklia_1

Everything about forms is written in the documentation: symfony.com/doc/current/book/forms.html#book-form-...
In the controller, create a form right away:

$form = $this->createForm(new SignInForm(), null, array(
    'action' => $this->generateUrl('login_check'),
    'method' => 'POST',
));

As far as I understood, your form doesn't need to pass the $user object. If you still need, then specify it instead of null.
Form parameters (action and method) should also be specified in the form class. Then it will be even easier:
$form = $this->createForm(new SignInForm());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question