私はユーザーが必須フィールドを埋める必要がある簡単な編集フォームを持っています。問題は必須フィールドの検証が表示されず、フィールドまたはデータも変更されないことです。Symfony 3でデータを更新
UPDATEは私が$form->isSubmitted()
のvar_dump、それはここでbool(false)
を示して私のコントローラです:
public function editAction(Request $request, $id) {
$company = $this->getDoctrine()
->getRepository('SwipeBundle:Company')
->find($id);
if(!$company) {
throw $this->createNotFoundException(
'No Company found for id '.$id
);
}
$form = $this->createForm(CompanyType::class, $company, array(
'action'=>$this->generateUrl('swipe_backend_company_edit', array('id'=>$company->getId())),
'method'=>'PUT'
));
if ($request->getMethod() == "POST") {
if ($form->isSubmitted()) {
// $em->persist($company);
// $em->flush();
echo "Update";
}
}
return $this->render('Backend/Company/edit.html.twig', array(
'form'=>$form->createView(),
'company'=>$company
));
}
そして、ここに私の小枝テンプレートの編集/更新のための
{% extends '::Backend/base.html.twig' %}
{% block body %}
<!-- Section -->
<section class="sections">
<!-- Side Bar -->
{% include '::Backend/side_menu_bar.html.twig' %}
<!-- Wrapper -->
<div id="administrator" class="wrapper">
<div class="mt40 pt30"> <!-- Container -->
<h1 class="mb10 bold">Edit Company</h1>
<p class="mb30">Fill up all the required fields for Company.</p>
{% if not form.vars.valid %}
<p class="alert note-error">
There are errors in your form. Please check the fields marked in red.
</p>
{% endif %}
<div class="alert note-error">
<p>Fields with asterisk (*) are required</p>
</div>
{% set url = path('swipe_backend_company_edit', { 'id': company.id }) %}
<form novalidate method="post" action="{{ url }}" class="p20 card mb30">
<div class="sections pb30 pt10">
<fieldset class="col span6">
{% set attr = {} %}
{% if form_errors(form.name) is not empty %}
{% set attr = attr|merge({ 'class': 'alert error'}) %}
{% endif %}
<label for="" class="input-required">
<strong>Company Name<span class="highlight-red">*</span>
</strong>
</label>
{{ form_widget(form.name, { 'attr': attr }) }}
{% if not form.name.vars.valid %}
<p class="mt10" style="color: #DC2B1B;">
{{ form.name.vars.errors[0].message }}
</p>
{% endif %}
</fieldset>
<fieldset class="col span6">
<strong>
{{ form_label(form.website) }}
</strong>
{{ form_widget(form.website) }}
</fieldset>
</div>
<div class="sections pb30 pt10">
{% set attr = {} %}
{% if form_errors(form.email_address) is not empty %}
{% set attr = attr|merge({ 'class': 'alert error'}) %}
{% endif %}
<label for="" class="input-required">
<strong>Company Email Address<span class="highlight-red">*</span>
</strong>
</label>
{{ form_widget(form.email_address, { 'attr': attr }) }}
{% if not form.email_address.vars.valid %}
<p class="mt10" style="color: #DC2B1B;">
{{ form.email_address.vars.errors[0].message }}
</p>
{% endif %}
</div>
<div class="sections pb30 pt10">
<fieldset class="col span6">
<strong>
{{ form_label(form.telephone_no) }}
</strong>
{{ form_widget(form.telephone_no) }}
</fieldset>
<fieldset class="col span6">
<strong>
{{ form_label(form.mobile_no) }}
</strong>
{{ form_widget(form.mobile_no) }}
</fieldset>
</div>
<div class="sections pb30 pt10">
{% set attr = {} %}
{% if form_errors(form.address) is not empty %}
{% set attr = attr|merge({ 'class': 'alert error'}) %}
{% endif %}
<label for="" class="input-required">
<strong>Company Address<span class="highlight-red">*</span>
</strong>
</label>
{{ form_widget(form.address, { 'attr': attr }) }}
{% if not form.address.vars.valid %}
<p class="mt10" style="color: #DC2B1B;">
{{ form.address.vars.errors[0].message }}
</p>
{% endif %}
</div>
<div class="text-right mt20 mb10">
<button class="btn btn-positive mt10 mr5">Update Company</button>
<button class="btn btn-positive mt10 mr5">Cancel</button>
</div>
{{ form_rest(form) }}
</form>
</div> <!-- Container End -->
</div> <!-- Wrapper End -->
</section> <!-- Section End -->
{% endblock %}
あなたには何が起こっているのか、何をしたいのか、何を試したのかを教えてください。 –