Skip to content
Permalink
Browse files

DefaultFormRenderer: strict type fix (#220)

fixes "TypeError: preg_split() expects parameter 2 to be string, null given" for GET form if action does not contain query parameters
  • Loading branch information...
rydercz authored and dg committed Apr 16, 2019
1 parent d9fc6d6 commit 85467ba6e58fd3ffbe5a6fa7be037e00a822925e
Showing with 44 additions and 1 deletion.
  1. +1 −1 src/Forms/Rendering/DefaultFormRenderer.php
  2. +43 −0 tests/Forms/Forms.renderer.6.phpt
@@ -167,7 +167,7 @@ public function renderBegin(): string
if ($this->form->isMethod('get')) {
$el = clone $this->form->getElementPrototype();
$query = parse_url($el->action, PHP_URL_QUERY);
$query = parse_url($el->action, PHP_URL_QUERY) ?: '';
$el->action = str_replace("?$query", '', $el->action);
$s = '';
foreach (preg_split('#[;&]#', $query, -1, PREG_SPLIT_NO_EMPTY) as $param) {
@@ -0,0 +1,43 @@
<?php
/**
* Test: Nette\Forms default rendering GET form.
*/
declare(strict_types=1);
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$form = new Nette\Forms\Form;
$form->setMethod('GET');
$form->setAction('link');
$form->addCheckboxList('list')
->setItems(['First', 'Second']);
$form->addHidden('userid');
$form->addSubmit('submit', 'Send');
$form->fireEvents();
Assert::match('<form action="link" method="get">
<table>
<tr>
<th><label></label></th>
<td><label><input type="checkbox" name="list[]" value="0">First</label><br><label><input type="checkbox" name="list[]" value="1">Second</label></td>
</tr>
<tr>
<th></th>
<td><input type="submit" name="_submit" value="Send" class="button"></td>
</tr>
</table>
<input type="hidden" name="userid" value=""><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->
</form>', $form->__toString(true));
Assert::same('link', $form->getAction());

0 comments on commit 85467ba

Please sign in to comment.
You can’t perform that action at this time.