0

I have the following controller:

public function postStuffAction(Request $request)
    {
        $form = $this->createFormBuilder()
            ->add("name", "text")
            ->getForm();

        $form->handleRequest($request);

        return $form->isValid(); //False
        //return $form->getErrorsAsString(); //No errors
    }

This is my form:

 <form enctype="multipart/form-data" method="post" action="http://mydomain/resource/1?XDEBUG_SESSION_START=appointmed">
     <input type="text" name="name" />
     <button class="btn btn-success" type="submit"> Upload file </button>
 </form>

This form lives in a different domain, it is not redenred as a twig template, is just a plain html form.

When the controller gets the request the form is always empty, what could be happenning?

1
  • What you mean with this form lives in a different domain? I see the action to another domain but I don't see why you build the form on the controller and try to validate it using handleRequest since that form it's not a Symfony2 form is just "another form" try to get the request as for example $request->get('name') and see if it has values and values are valid or something other way to go Commented Aug 10, 2014 at 22:05

1 Answer 1

2

You can only use use FormBuilder's built in validation function if you are creating the form and presenting it in Twig.

If you want to validate input from a manually built form or a form posted from another domain then you need to access the Request object, map it to your entity and then call the validator service. For example:

// Setup entity and map Request
$entity = new Entity();
$entity->setName($request->get('name', null));

// Validate the entity
$validator = $this->get('validator');
$errors = $validator->validate($entity);
if (count($errors) > 0) {           
    return $errors
}
Sign up to request clarification or add additional context in comments.

2 Comments

okay, but I'm not able to get the data sent from the client, whenever y print $request->request->all() I always get null.
What do you see if you just dump the whole $request object instead of using $request->request->all()?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.