Я использую Symfony 4.2.11 в PHP 7.2 с этим кодом:
<?php
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\LessThan;
class FormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('startDate', DateType::class, [
"required" => true,
'input' => 'datetime_immutable',
/*'constraints' => [
new LessThan([
'propertyPath' => 'parent.all[endDate].data'
]),
]*/
]);
$builder->add('endDate', DateType::class, [
"required" => true,
'input' => 'datetime_immutable',
}
}
$form = $this->formFactory->create(FormType::class);
//$form->submit($formData);
$form->submit([
"startDate" => new \DateTimeImmutable(),
"endDate" => new \DateTimeImmutable()
]);
if (!$form->isValid()) {
echo("Form invalid");
}
Однако, когда я запускаю этот код, он выводит «Неверная форма». Как мне исправить этот код, чтобы он принимал все DateTimeImmutable
объекты?