How to implement the form, that accepts the following JSON-Object? I have defined no models, because I don't need them. The data are sent
{
"type_of_error": "logic error",
"severity": "normal",
"what_did_you_do": "something",
"what_happened": "blue screen",
"which_result": "full satisfaction",
"requests": [
{
"url": "/api/v1/agent/statistic"
}
]
}
I already have begun to build the form:
class ErrorReportFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type_of_error', TextType::class, [
'empty_data' => '',
'constraints' => [
new NotBlank()
]
])
->add('severity', TextType::class, [
'empty_data' => '',
'constraints' => [
new NotBlank()
]
])
->add('what_did_you_do', TextType::class, [
'empty_data' => '',
'constraints' => [
new NotBlank()
]
])
->add('what_happened', TextType::class, [
'empty_data' => '',
'constraints' => [
new NotBlank(),
]
])
->add('which_result', TextType::class, [
'empty_data' => '',
'constraints' => [
new NotBlank(),
]
])
->add('requests', CollectionType::class, [
'entry_type' => RequestsFormType::class,
])
;
}
And I have defined RequestsFormType like this. What is here wrong? It looks, as if RequestsFormType would not be accepted.
class RequestsFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('url', TextType::class, [
'empty_data' => '',
'constraints' => [
new NotBlank()
]
]);
}
public function getBlockPrefix()
{
return '';
}
}