我尝试在同一页面上进行简单的登录注册。
- 一种登记表
- 一种登录表格。
我设法在我想要的页面上呈现 2 个表单,但是如果我尝试提交注册表单,它会给我一个消息,即另一个表单不能为空。
在我尝试合并页面之前,我的注册没有任何问题,我的登录没有(刚刚创建表单)我的代码:
AccountController.php
呈现给模板的文件。
表单创建已在 inRegistrationType.php
和 in 中实现LoginType.php
<?php
namespace Spyros\MapBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Spyros\MapBundle\Form\Type\RegistrationType;
use Spyros\MapBundle\Form\Type\LoginType;
use Spyros\MapBundle\Form\Model\Registration;
use Spyros\MapBundle\Form\Model\Login;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class AccountController extends Controller
{
public function registerAction()
{
$registration = new Registration();
$form1 = $this->createForm(new RegistrationType() , $registration, array(
'action' => $this->generateUrl('account_create') ,
));
$login = new Login();
$form2 = $this->createForm(new LoginType() , $login, array(
'action' => $this->generateUrl('account_create') ,
));
return $this->render('SpyrosMapBundle:Account:register.html.twig', array(
'form1' => $form1->createView() ,
'form2' => $form2->createView()
));
}
public function createAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$form1 = $this->createForm(new RegistrationType() , new Registration());
$form1 > handleRequest($request);
if ($form1->isValid())
{
$registration = $form1->getData();
$em->persist($registration->getUser());
$em->flush();
echo "<p>hi</p>";
}
return $this->render('SpyrosMapBundle:Account:register.html.twig', array(
'form1' => $form1->createView()
));
}
}
register.html.twig:
{% extends 'SpyrosMapBundle::rightform.html.twig' %}
{% form_theme form1 'bootstrap_3_layout.html.twig' %}
{% form_theme form2 'bootstrap_3_layout.html.twig' %}
{% block body %}
<body>
<section class="container">
<section class="row">
<section class="col col-lg-9">
{{ form_start(form2 , {'attr': {'class': 'form-inline'}} )}}
{{ form_row(form2.user.email)}}
{{ form_row(form2.user.plainPassword)}}
<div id="inline">
{{ form_row(form2.Login) }}
</div>
</section>
<section class="col col-lg-3">
{{ form(form1) }}
</section>
</section>
</section>
</body>
{% endblock %}
我的视图页面:
我如何在没有 form2 的情况下提交我的注册表单(form1)给我一条消息以填写其字段。