Symfony rendering form only in first row of collection

Multi tool use
perhaps somebody can help me because I'm digging forums and documentation since a week how to render a table where I have a form in 3rd column.
I have a class CollectionController with following snippet:
return $this->render(
'vollmachtapp/pages/collections/list2.html.twig',
[
'attachmentForm' => $attachmentForm->createView(),
'list' => $apiClient->listAllVollmachten()
]
);
The attachmentForm looks like this:
$attachmentForm = $this->createForm( SimpleAttachmentType::class, $attachment );
Here is my SimpleAttachmentType:
class SimpleAttachmentType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
$builder
->add('file', FileType::class)
->add('vollmachtId', HiddenType::class)
->add('save', SubmitType::class, ['label' => 'Vollmacht hochladen']);
Now I'm using a twig which looks like:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Vollmacht ID</th>
<th>Users</th>
<th>Upload/Download</th>
</tr>
</thead>
<tbody>
% for collection in list.items %
<tr>
<td> collection.id </td>
<td>
% for user in collection.users %
<a href=" url('user_detail', 'id': user.id) ">
user.name
</a><br>
% endfor %
</td>
<td>
<a href=" url('downloadVollmacht', 'id': user.id) "><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
% if(app.user.role == "admin") %
<hr>
<div class="text-center mtop20">
form_start(attachmentForm, method: 'POST')
% if not attachmentForm.vars.valid %
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
form_errors(attachmentForm.file)
</div>
% endif %
form_widget(attachmentForm.vollmachtId, 'name': vollmachtId, 'value': collection.id)
form_widget(attachmentForm.file)
<br />
form_widget(attachmentForm.save, attr: 'class': 'btn-left btn btn-sm btn-primary')
form_end(attachmentForm)
</div>
% endif %
</td>
</tr>
% endfor %
</tbody>
</table>
The problem I have, the form is only rendered in the 1st row of the table. Can anybody tell me what I'm doing wrong and have to change to get it work?
Thanks and best regards,
Michael Obster
php forms symfony html-table
add a comment |
perhaps somebody can help me because I'm digging forums and documentation since a week how to render a table where I have a form in 3rd column.
I have a class CollectionController with following snippet:
return $this->render(
'vollmachtapp/pages/collections/list2.html.twig',
[
'attachmentForm' => $attachmentForm->createView(),
'list' => $apiClient->listAllVollmachten()
]
);
The attachmentForm looks like this:
$attachmentForm = $this->createForm( SimpleAttachmentType::class, $attachment );
Here is my SimpleAttachmentType:
class SimpleAttachmentType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
$builder
->add('file', FileType::class)
->add('vollmachtId', HiddenType::class)
->add('save', SubmitType::class, ['label' => 'Vollmacht hochladen']);
Now I'm using a twig which looks like:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Vollmacht ID</th>
<th>Users</th>
<th>Upload/Download</th>
</tr>
</thead>
<tbody>
% for collection in list.items %
<tr>
<td> collection.id </td>
<td>
% for user in collection.users %
<a href=" url('user_detail', 'id': user.id) ">
user.name
</a><br>
% endfor %
</td>
<td>
<a href=" url('downloadVollmacht', 'id': user.id) "><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
% if(app.user.role == "admin") %
<hr>
<div class="text-center mtop20">
form_start(attachmentForm, method: 'POST')
% if not attachmentForm.vars.valid %
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
form_errors(attachmentForm.file)
</div>
% endif %
form_widget(attachmentForm.vollmachtId, 'name': vollmachtId, 'value': collection.id)
form_widget(attachmentForm.file)
<br />
form_widget(attachmentForm.save, attr: 'class': 'btn-left btn btn-sm btn-primary')
form_end(attachmentForm)
</div>
% endif %
</td>
</tr>
% endfor %
</tbody>
</table>
The problem I have, the form is only rendered in the 1st row of the table. Can anybody tell me what I'm doing wrong and have to change to get it work?
Thanks and best regards,
Michael Obster
php forms symfony html-table
add a comment |
perhaps somebody can help me because I'm digging forums and documentation since a week how to render a table where I have a form in 3rd column.
I have a class CollectionController with following snippet:
return $this->render(
'vollmachtapp/pages/collections/list2.html.twig',
[
'attachmentForm' => $attachmentForm->createView(),
'list' => $apiClient->listAllVollmachten()
]
);
The attachmentForm looks like this:
$attachmentForm = $this->createForm( SimpleAttachmentType::class, $attachment );
Here is my SimpleAttachmentType:
class SimpleAttachmentType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
$builder
->add('file', FileType::class)
->add('vollmachtId', HiddenType::class)
->add('save', SubmitType::class, ['label' => 'Vollmacht hochladen']);
Now I'm using a twig which looks like:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Vollmacht ID</th>
<th>Users</th>
<th>Upload/Download</th>
</tr>
</thead>
<tbody>
% for collection in list.items %
<tr>
<td> collection.id </td>
<td>
% for user in collection.users %
<a href=" url('user_detail', 'id': user.id) ">
user.name
</a><br>
% endfor %
</td>
<td>
<a href=" url('downloadVollmacht', 'id': user.id) "><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
% if(app.user.role == "admin") %
<hr>
<div class="text-center mtop20">
form_start(attachmentForm, method: 'POST')
% if not attachmentForm.vars.valid %
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
form_errors(attachmentForm.file)
</div>
% endif %
form_widget(attachmentForm.vollmachtId, 'name': vollmachtId, 'value': collection.id)
form_widget(attachmentForm.file)
<br />
form_widget(attachmentForm.save, attr: 'class': 'btn-left btn btn-sm btn-primary')
form_end(attachmentForm)
</div>
% endif %
</td>
</tr>
% endfor %
</tbody>
</table>
The problem I have, the form is only rendered in the 1st row of the table. Can anybody tell me what I'm doing wrong and have to change to get it work?
Thanks and best regards,
Michael Obster
php forms symfony html-table
perhaps somebody can help me because I'm digging forums and documentation since a week how to render a table where I have a form in 3rd column.
I have a class CollectionController with following snippet:
return $this->render(
'vollmachtapp/pages/collections/list2.html.twig',
[
'attachmentForm' => $attachmentForm->createView(),
'list' => $apiClient->listAllVollmachten()
]
);
The attachmentForm looks like this:
$attachmentForm = $this->createForm( SimpleAttachmentType::class, $attachment );
Here is my SimpleAttachmentType:
class SimpleAttachmentType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
$builder
->add('file', FileType::class)
->add('vollmachtId', HiddenType::class)
->add('save', SubmitType::class, ['label' => 'Vollmacht hochladen']);
Now I'm using a twig which looks like:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Vollmacht ID</th>
<th>Users</th>
<th>Upload/Download</th>
</tr>
</thead>
<tbody>
% for collection in list.items %
<tr>
<td> collection.id </td>
<td>
% for user in collection.users %
<a href=" url('user_detail', 'id': user.id) ">
user.name
</a><br>
% endfor %
</td>
<td>
<a href=" url('downloadVollmacht', 'id': user.id) "><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
% if(app.user.role == "admin") %
<hr>
<div class="text-center mtop20">
form_start(attachmentForm, method: 'POST')
% if not attachmentForm.vars.valid %
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
form_errors(attachmentForm.file)
</div>
% endif %
form_widget(attachmentForm.vollmachtId, 'name': vollmachtId, 'value': collection.id)
form_widget(attachmentForm.file)
<br />
form_widget(attachmentForm.save, attr: 'class': 'btn-left btn btn-sm btn-primary')
form_end(attachmentForm)
</div>
% endif %
</td>
</tr>
% endfor %
</tbody>
</table>
The problem I have, the form is only rendered in the 1st row of the table. Can anybody tell me what I'm doing wrong and have to change to get it work?
Thanks and best regards,
Michael Obster
php forms symfony html-table
php forms symfony html-table
asked Nov 11 '18 at 22:05
MikeO
1091513
1091513
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Your Main Problem is, that you cant seperate this form_snippet multiple times
form_start(attachmentForm, method: 'POST')
Your form Start and form End have to be wrapping the hole form. if your want that form also in all tags you cant write the start form twig snippet only in one . You have to write some code like that:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Vollmacht ID</th>
<th>Users</th>
<th>Upload/Download</th>
</tr>
</thead>
<tbody>
% for collection in list.items %
<tr>
form_start(attachmentForm, method: 'POST')
<td> collection.id </td>
<td>
% for user in collection.users %
<a href=" url('user_detail', 'id': user.id) ">
user.name
</a><br>
% endfor %
</td>
<td>
<a href=" url('downloadVollmacht', 'id': user.id) "><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
% if(app.user.role == "admin") %
<hr>
<div class="text-center mtop20">
% if not attachmentForm.vars.valid %
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
form_errors(attachmentForm.file)
</div>
% endif %
form_widget(attachmentForm.vollmachtId, 'name': vollmachtId, 'value': collection.id)
form_widget(attachmentForm.file)
<br />
form_widget(attachmentForm.save, attr: 'class': 'btn-left btn btn-sm btn-primary')
</div>
% endif %
</td>
form_end(attachmentForm)
</tr>
% endfor %
</tbody>
</table>
But maybe its reconstruct your HTML markup a lil bit.
Thank you I'll try that. And I think I understand the problem now.
– MikeO
Nov 12 '18 at 13:20
add a comment |
You should take a look at how to work with a collection of forms in symfony Documentation :
https://symfony.com/doc/current/reference/forms/types/collection.html
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253722%2fsymfony-rendering-form-only-in-first-row-of-collection%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your Main Problem is, that you cant seperate this form_snippet multiple times
form_start(attachmentForm, method: 'POST')
Your form Start and form End have to be wrapping the hole form. if your want that form also in all tags you cant write the start form twig snippet only in one . You have to write some code like that:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Vollmacht ID</th>
<th>Users</th>
<th>Upload/Download</th>
</tr>
</thead>
<tbody>
% for collection in list.items %
<tr>
form_start(attachmentForm, method: 'POST')
<td> collection.id </td>
<td>
% for user in collection.users %
<a href=" url('user_detail', 'id': user.id) ">
user.name
</a><br>
% endfor %
</td>
<td>
<a href=" url('downloadVollmacht', 'id': user.id) "><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
% if(app.user.role == "admin") %
<hr>
<div class="text-center mtop20">
% if not attachmentForm.vars.valid %
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
form_errors(attachmentForm.file)
</div>
% endif %
form_widget(attachmentForm.vollmachtId, 'name': vollmachtId, 'value': collection.id)
form_widget(attachmentForm.file)
<br />
form_widget(attachmentForm.save, attr: 'class': 'btn-left btn btn-sm btn-primary')
</div>
% endif %
</td>
form_end(attachmentForm)
</tr>
% endfor %
</tbody>
</table>
But maybe its reconstruct your HTML markup a lil bit.
Thank you I'll try that. And I think I understand the problem now.
– MikeO
Nov 12 '18 at 13:20
add a comment |
Your Main Problem is, that you cant seperate this form_snippet multiple times
form_start(attachmentForm, method: 'POST')
Your form Start and form End have to be wrapping the hole form. if your want that form also in all tags you cant write the start form twig snippet only in one . You have to write some code like that:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Vollmacht ID</th>
<th>Users</th>
<th>Upload/Download</th>
</tr>
</thead>
<tbody>
% for collection in list.items %
<tr>
form_start(attachmentForm, method: 'POST')
<td> collection.id </td>
<td>
% for user in collection.users %
<a href=" url('user_detail', 'id': user.id) ">
user.name
</a><br>
% endfor %
</td>
<td>
<a href=" url('downloadVollmacht', 'id': user.id) "><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
% if(app.user.role == "admin") %
<hr>
<div class="text-center mtop20">
% if not attachmentForm.vars.valid %
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
form_errors(attachmentForm.file)
</div>
% endif %
form_widget(attachmentForm.vollmachtId, 'name': vollmachtId, 'value': collection.id)
form_widget(attachmentForm.file)
<br />
form_widget(attachmentForm.save, attr: 'class': 'btn-left btn btn-sm btn-primary')
</div>
% endif %
</td>
form_end(attachmentForm)
</tr>
% endfor %
</tbody>
</table>
But maybe its reconstruct your HTML markup a lil bit.
Thank you I'll try that. And I think I understand the problem now.
– MikeO
Nov 12 '18 at 13:20
add a comment |
Your Main Problem is, that you cant seperate this form_snippet multiple times
form_start(attachmentForm, method: 'POST')
Your form Start and form End have to be wrapping the hole form. if your want that form also in all tags you cant write the start form twig snippet only in one . You have to write some code like that:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Vollmacht ID</th>
<th>Users</th>
<th>Upload/Download</th>
</tr>
</thead>
<tbody>
% for collection in list.items %
<tr>
form_start(attachmentForm, method: 'POST')
<td> collection.id </td>
<td>
% for user in collection.users %
<a href=" url('user_detail', 'id': user.id) ">
user.name
</a><br>
% endfor %
</td>
<td>
<a href=" url('downloadVollmacht', 'id': user.id) "><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
% if(app.user.role == "admin") %
<hr>
<div class="text-center mtop20">
% if not attachmentForm.vars.valid %
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
form_errors(attachmentForm.file)
</div>
% endif %
form_widget(attachmentForm.vollmachtId, 'name': vollmachtId, 'value': collection.id)
form_widget(attachmentForm.file)
<br />
form_widget(attachmentForm.save, attr: 'class': 'btn-left btn btn-sm btn-primary')
</div>
% endif %
</td>
form_end(attachmentForm)
</tr>
% endfor %
</tbody>
</table>
But maybe its reconstruct your HTML markup a lil bit.
Your Main Problem is, that you cant seperate this form_snippet multiple times
form_start(attachmentForm, method: 'POST')
Your form Start and form End have to be wrapping the hole form. if your want that form also in all tags you cant write the start form twig snippet only in one . You have to write some code like that:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Vollmacht ID</th>
<th>Users</th>
<th>Upload/Download</th>
</tr>
</thead>
<tbody>
% for collection in list.items %
<tr>
form_start(attachmentForm, method: 'POST')
<td> collection.id </td>
<td>
% for user in collection.users %
<a href=" url('user_detail', 'id': user.id) ">
user.name
</a><br>
% endfor %
</td>
<td>
<a href=" url('downloadVollmacht', 'id': user.id) "><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
% if(app.user.role == "admin") %
<hr>
<div class="text-center mtop20">
% if not attachmentForm.vars.valid %
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
form_errors(attachmentForm.file)
</div>
% endif %
form_widget(attachmentForm.vollmachtId, 'name': vollmachtId, 'value': collection.id)
form_widget(attachmentForm.file)
<br />
form_widget(attachmentForm.save, attr: 'class': 'btn-left btn btn-sm btn-primary')
</div>
% endif %
</td>
form_end(attachmentForm)
</tr>
% endfor %
</tbody>
</table>
But maybe its reconstruct your HTML markup a lil bit.
answered Nov 12 '18 at 11:29


episch
304114
304114
Thank you I'll try that. And I think I understand the problem now.
– MikeO
Nov 12 '18 at 13:20
add a comment |
Thank you I'll try that. And I think I understand the problem now.
– MikeO
Nov 12 '18 at 13:20
Thank you I'll try that. And I think I understand the problem now.
– MikeO
Nov 12 '18 at 13:20
Thank you I'll try that. And I think I understand the problem now.
– MikeO
Nov 12 '18 at 13:20
add a comment |
You should take a look at how to work with a collection of forms in symfony Documentation :
https://symfony.com/doc/current/reference/forms/types/collection.html
add a comment |
You should take a look at how to work with a collection of forms in symfony Documentation :
https://symfony.com/doc/current/reference/forms/types/collection.html
add a comment |
You should take a look at how to work with a collection of forms in symfony Documentation :
https://symfony.com/doc/current/reference/forms/types/collection.html
You should take a look at how to work with a collection of forms in symfony Documentation :
https://symfony.com/doc/current/reference/forms/types/collection.html
answered Nov 12 '18 at 10:16
Yoann Mir
865
865
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253722%2fsymfony-rendering-form-only-in-first-row-of-collection%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
g9KG,18y1z,fZChnrINe7e5JhxB1HhqWHvAibqzcbU1,t2c,NxfCfBKh9bOdx5ahrR0PrDK