Symfony2 invalid form without errors

前端 未结 11 831
孤独总比滥情好
孤独总比滥情好 2020-12-01 01:46

I\'ve got a problem with a Symfony2 generated CRUD form. (With MongoDB Documents, but I do not think that this is related)

In my controller\'s createAction() method,

11条回答
  •  星月不相逢
    2020-12-01 02:15

    If you are sending datas via AJAX, you may have missed to include the form's name on your datas keys and therefore are "victim" of …

    # line 100 of Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php 
    // Don't submit the form if it is not present in the request
    

    Which means, while trying to handle the request, the request processing mechanism did not find your form's name inside GET/POST datas (meaning as an array).

    When you render a form the usual way, each of its fields contain your form's name as a prefix into their name attribute my_form[child_field_name].

    When using ajax, add your form's name as a prefix in datas !

    data : {
        "my_form" : {
           "field_one" : "field_one_value"
           ...
        }
    }
    

提交回复
热议问题