Optimized register form

This commit is contained in:
Kevin Frantz 2018-09-06 17:47:47 +02:00
parent 56fb409477
commit d9fc547f85
5 changed files with 19 additions and 23 deletions

View File

@ -2,3 +2,4 @@ twig:
paths: ['%kernel.project_dir%/templates'] paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%' debug: '%kernel.debug%'
strict_variables: '%kernel.debug%' strict_variables: '%kernel.debug%'
form_themes: ['bootstrap_4_layout.html.twig']

View File

@ -5,6 +5,10 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use App\Entity\User;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
/** /**
* *
@ -29,6 +33,12 @@ class UserController extends AbstractController implements UserControllerInterfa
*/ */
public function register(): Response public function register(): Response
{ {
return $this->render("user/register.html.twig"); $user = new User();
$form = $this->createFormBuilder($user)
->add('username', TextType::class)
->add('password', PasswordType::class)
->add('save', SubmitType::class,['label' => 'register'])
->getForm();
return $this->render("user/register.html.twig",['form'=>$form->createView()]);
} }
} }

View File

@ -12,7 +12,7 @@ trait PasswordAttribut {
*/ */
protected $password; protected $password;
public function getPassword():string public function getPassword():?string
{ {
return $this->password; return $this->password;
} }

View File

@ -13,7 +13,7 @@ trait UsernameAttribut{
*/ */
protected $username; protected $username;
public function getUsername():string public function getUsername():?string
{ {
return $this->username; return $this->username;
} }

View File

@ -1,25 +1,10 @@
{% extends "frames/default.html.twig" %} {% extends "frames/default.html.twig" %}
{% block title %} {% block title %}
register {% trans %}register{% endtrans %}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<h1>Register</h1> <h1>{% trans %}register{% endtrans %}</h1>
<form method="post"> {{ form_start(form) }}
<div class="form-group"> {{ form_widget(form) }}
<label for="email">Email address</label> <input type="email" {{ form_end(form) }}
class="form-control" id="email" aria-describedby="emailHelp"
name="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="name">Username</label> <input type="email"
class="form-control" id="name" aria-describedby="emailHelp"
name="name" placeholder="Enter Username">
</div>
<div class="form-group">
<label for="password">Password</label> <input type="password"
class="form-control" id="password" name="password"
placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
{% endblock %} {% endblock %}