Php Craue表单流在$flow上返回false->;最后一步中的isValid()
我用创建了表单向导,它一直工作到最后一步,$flow->isValid()失败,并且它不断地呈现最后一步,而不是转到所需的表单向导结束操作 以下是理解我犯错误的地方所需的代码: 控制器:Php Craue表单流在$flow上返回false->;最后一步中的isValid(),php,forms,symfony,craueformflow,Php,Forms,Symfony,Craueformflow,我用创建了表单向导,它一直工作到最后一步,$flow->isValid()失败,并且它不断地呈现最后一步,而不是转到所需的表单向导结束操作 以下是理解我犯错误的地方所需的代码: 控制器: public function indexAction(Activity $activity) { $currency = $this->getDoctrine()->getRepository('MycompanyUtilBundle:UtilCurrency')->find(1);
public function indexAction(Activity $activity)
{
$currency = $this->getDoctrine()->getRepository('MycompanyUtilBundle:UtilCurrency')->find(1);
$booking = new Booking();
$booking->setActivity($activity)
->setCurrency($currency)
->setReferenceCode(uniqid())
->setUserAccount($this->getDoctrine()->getRepository('MycompanySettingsBundle:UserAccount')->find(1));
$flow = $this->get('mycompany.form.flow.Booking');
$flow->bind($booking);
$form = $flow->createForm();
if ($flow->isValid($form)) {
$flow->saveCurrentStepData($form);
if ($flow->nextStep()) {
$form = $flow->createForm();
} else {
return new JsonResponse(['Status' => 'Form is valid']);
}
}
return $this->render(
'@MycompanyDemoBundle/Default/booking.flow.html.twig',
[
'form' => $form->createView(),
'flow' => $flow,
'activity' => $activity->getTitle(),
'formData' => $booking,
'error' => $form->getErrors(true, true),
]
);
}
services.yml:
mycompany.form.Booking:
class: mycompany\BookingBundle\Form\BookingType
tags:
- { name: form.type, alias: mycompany_bookingbundle_booking_form }
mycompany.form.flow.Booking:
class: mycompany\BookingBundle\Form\BookingFlow
parent: craue.form.flow
scope: request
calls:
- [ setFormType, [ @mycompany.form.Booking ] ]
BookingType.php:
public function buildForm(FormBuilderInterface $builder, array $options)
{
switch ($options['flow_step']) {
case 1:
$builder
->add(
'activity',
'entity',
[
'class' => 'Mycompany\ActivityBundle\Entity\Activity',
'property' => 'title',
]
)
->add(
'scheduledDeparture',
'entity',
[
'class' => 'Mycompany\ActivityBundle\Entity\ActivityScheduledDeparture',
'property' => 'departureDateTimeString',
'empty_value' => 'Select departure time',
]
)
->add(
'payer',
new CrmContactType()
);
break;
case 2:
$builder
->add(
'numberOfAdults',
'choice',
[
'choices' => range(1, 5),
'empty_value' => 'Select number of adult travellers'
]
)
->add(
'numberOfChildren',
'choice',
[
'choices' => range(1, 5),
'empty_value' => 'Select number of child travellers'
]
);
}
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
[
'data_class' => 'Mycompany\BookingBundle\Entity\Booking',
]
);
}
记账流程:
protected function loadStepsConfig()
{
return
[
[
'label' => 'Select tour',
'type' => $this->formType,
],
[
'label' => 'Select travellers',
'type' => $this->formType,
],
[
'label' => 'Confirmation',
],
];
}
在细枝文件的末尾:
{% stylesheets '@CraueFormFlowBundle/Resources/assets/css/buttons.css' %}
<link type="text/css" rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
<div>
Steps:
{% include '@CraueFormFlow/FormFlow/stepList.html.twig' %}
</div>
{{ form_start(form) }}
{{ form_errors(form) }}
{{ activity }}
{{ form_rest(form) }}
{% include '@CraueFormFlow/FormFlow/buttons.html.twig' %}
{{ form_end(form) }}
<div>
Errors:
{{ dump(error) }}
</div>
<div>
Form:
{{ dump(form) }}
</div>
{%stylesheets'@CraueFormFlowBundle/Resources/assets/css/buttons.css%}
{%endstylesheets%}
步骤:
{%include'@CraueFormFlow/FormFlow/stepList.html.twig%}
{{form_start(form)}}
{{form_errors(form)}}
{{activity}}
{{form_rest(form)}
{%include'@CraueFormFlow/FormFlow/buttons.html.twig%}
{{form_end(form)}}
错误:
{{dump(error)}
表格:
{{dump(form)}
根本没有额外的验证,只是该字段不能为空。我进入了最后一步,当我点击Finish
按钮时,我以为Symfony会生成带有“Form is valid”值的JSON,但我得到的只是一次又一次的最后一步。
当我调试该部分时,单击finish会使$flow->isValid($form)为false,尽管前面的每个步骤都是true,我无法在这里返回JSON响应
我还在twig中转储form和form->getErrors值,但没有什么类似于我有一些错误。如果我尝试持久化该数据,它将成功持久化
我在捆绑包的git页面上没有找到解决方案。
你们知道我应该在哪里找到解决方案吗?解决方案的行是: app/config/config.yml
csrf_protection:
enabled: true
现在,当我想到这一点时,就明白了为什么需要csrf_令牌来处理CraueFormFlowBundle示例中给出的当前工作流