$form.addHidden('id') render input type='hidden' after submit button missing $_POST['id']
tablecell opened this issue · comments
Version: 2
Bug Description
...
addHidden('id') render html input type="hidden" after input type="submit
when click submit missing $_POST['id']
Steps To Reproduce
php
$form = new Form();
$data=['name'=>'test','id'=>100,'content_html'=>'xxx'];
$form->addText('name', 'Název: ')
->addRule(Form::FILLED, 'Název musí být vyplněn.');
$form->addHidden('id');
$form->addTextarea('content_html', 'Obsah: ')
->addRule(Form::FILLED, 'Obsah musí být vyplněn.');
$form->addSubmit('send', 'Send');
$form->setAction("/post.php' );
$form->setDefaults( $data);
$template = app()->template('templates/admin.articles.edit.latte');
$template['articleForm'] = $form;
$template->render();
tpl
templates/admin.articles.edit.latte
{control articleForm}
Expected Behavior
... A clear and concise description of what you expected to happen.
<form action="/post.php" method="post" >
<input type="text" class="text" name="name" value="test" >
<input type="hidden" name="id" value="100">
<textarea name="content_html">xxx </textarea>
<input type="submit" class="button" name="send" value="Send" >
</form>
but html is
<form action="/admin/pridat-clanek.html" method="post" >
<input type="text" class="text" name="name" value="test" >
<textarea name="content_html">xxx </textarea>
<input type="submit" class="button" name="send" value="Send" >
<input type="hidden" name="id" value="100">
</form>
click Submit missiing $_POST['id']
post.php
<?php
if ($form->isSubmitted() && $form->isValid()) {
$values = $form->getValues();
print_r($values);exit;
}
Array ( [name] =>test [content_html] => xxx
Possible Solution
... Only if you have suggestions on a fix for the bug
The problem will be somewhere else, it doesn't matter if hidden is after the button.
in post.php ,how get posted hidden field 'id' value by $form ?
if ($form->isSubmitted() && $form->isValid()) {
$values = $form->getValues();
print_r($values);exit;
}
Array ( [name] =>test [content_html] => xxx
$values has no 'id' field value
Try the forum.nette.org