Permalink
Browse files

feature #236 Add an example about how to use the form's buttons (voro…

…nkovich)

This PR was squashed before being merged into the master branch (closes #236).

Discussion
----------

Add an example about how to use the form's buttons

Commits
-------

cdcd412 Add an example about how to use the form's buttons
  • Loading branch information...
2 parents 36a93fd + cdcd412 commit e2d723cb48abfab317dabc2b679c7a4dd9750443 @javiereguiluz javiereguiluz committed Nov 1, 2015
@@ -112,6 +112,10 @@
<source>label.create_post</source>
<target>Create post</target>
</trans-unit>
+ <trans-unit id="label.save_and_create_new">
+ <source>label.save_and_create_new</source>
+ <target>Save and create new</target>
+ </trans-unit>
<trans-unit id="action.back_to_list">
<source>action.back_to_list</source>
<target>Back to the post list</target>
@@ -5,8 +5,6 @@
{% block main %}
<h1>{{ 'title.post_list'|trans }}</h1>
- {{ include('default/_flash_messages.html.twig') }}
-
<table class="table table-striped">
<thead>
<tr>
@@ -5,9 +5,21 @@
{% block main %}
<h1>{{ 'title.post_new'|trans }}</h1>
- {{ include('admin/blog/_form.html.twig', {
- include_back_to_home_link: true,
- }) }}
+ {{ form_start(form) }}
+ {{ form_row(form.title) }}
+ {{ form_row(form.summary) }}
+ {{ form_row(form.content) }}
+ {{ form_row(form.authorEmail) }}
+ {{ form_row(form.publishedAt) }}
+
+ <input type="submit" value="{{ 'label.create_post'|trans }}" class="btn btn-primary" />
+
+ {{ form_widget(form.saveAndCreateNew, { label: 'label.save_and_create_new'|trans, attr: { class: 'btn btn-primary' } }) }}
+
+ <a href="{{ path('admin_post_index') }}" class="btn btn-link">
+ {{ 'action.back_to_list'|trans }}
+ </a>
+ {{ form_end(form) }}
{% endblock %}
{% block sidebar %}
@@ -98,6 +98,8 @@
{% block body %}
<div class="row">
<div id="main" class="col-sm-9">
+ {{ include('default/_flash_messages.html.twig') }}
+
{% block main %}{% endblock %}
</div>
@@ -72,7 +72,10 @@ public function newAction(Request $request)
{
$post = new Post();
$post->setAuthorEmail($this->getUser()->getEmail());
- $form = $this->createForm(new PostType(), $post);
+
+ // See http://symfony.com/doc/current/book/forms.html#submitting-forms-with-multiple-buttons
+ $form = $this->createForm(new PostType(), $post)
+ ->add('saveAndCreateNew', 'submit');
$form->handleRequest($request);
@@ -93,6 +96,10 @@ public function newAction(Request $request)
// See http://symfony.com/doc/current/book/controller.html#flash-messages
$this->addFlash('success', 'post.created_successfully');
+ if ($form->get('saveAndCreateNew')->isClicked()) {
+ return $this->redirectToRoute('admin_post_new');
+ }
+
return $this->redirectToRoute('admin_post_index');
}

0 comments on commit e2d723c

Please sign in to comment.