Form s GET
- phx
- Člen | 651
Zdravim…
Musim Davida pochvalit, ze Form konecne funguji spravne s metodou GET, ale je tam jeden drobny problem. V podstate pri generovani formulare jsou vygenerovany hidden polozky s persistentnima parametrama a spol. Jenze co kdyz jiz neco takoveho ve formulari existuje? Napriklad Opera se chova zvlastne (odesle vetsi value → jednou z hidden jednou uzivatelsky zadany).
Proto by bylo vhodne pred generovani overovat zda ve formulari jiz neco takoveho neni!!!
Osobne pouzivam GET formular ke zmene presistentnich parametru (filtrovani vypisu tabulky). A proto na tento problem narazim. Jedine schudne reseni je tedy but si opravit Form (zasah do Nette) nebo odesilat pres POST a presmerovavat, coz neni 2× cool.
DEKUJI za opravu.
Editoval phx (11. 9. 2009 14:46)
- David Grudl
- Nette Core | 8218
Můžeš prosím ověřit tento fix:
index 1964e14..e166d38 100644
--- a/Nette/Forms/Renderers/ConventionalRenderer.php
+++ b/Nette/Forms/Renderers/ConventionalRenderer.php
@@ -246,7 +246,10 @@ class ConventionalRenderer extends /*Nette\*/Object implements IFormRenderer
if (isset($uri[1])) {
foreach (explode('&', $uri[1]) as $param) {
$parts = explode('=', $param, 2);
- $s .= Html::el('input', array('type' => 'hidden', 'name' => urldecode($parts[0]), 'value' => urldecode($parts[1])));
+ $name = urldecode($parts[0]);
+ if (!isset($this->form[$name])) {
+ $s .= Html::el('input', array('type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])));
+ }
}
$s = "\n\t" . $this->getWrapper('hidden container')->setHtml($s);
}
- phx
- Člen | 651
Nejde.
Hazi mi to chybu: Warning: Call to undefined method HiddenField::getComponent(). in /srv/www/vks.inet-servis.cz/src/libs/Nette/Forms/Form.php on line 758
A dela to radek:
if (!isset($this->form[$name])) {
Osobne jsem to takto zkousel a vysledek byl stejny (zahada) a nakonec jsem to resil takto:
public function renderBegin()
{
$this->counter = 0;
$controls = array();
foreach ($this->form->getControls() as $control) {
$controls[$control->getName()] = true;
$control->setOption('rendered', FALSE);
}
if (strcasecmp($this->form->getMethod(), 'get') === 0) {
$el = clone $this->form->getElementPrototype();
$uri = explode('?', (string) $el->action, 2);
$el->action = $uri[0];
$s = '';
if (isset($uri[1])) {
foreach (explode('&', $uri[1]) as $param) {
$parts = explode('=', $param, 2);
if (isset($controls[urldecode($parts[0])])) {
continue;
}
$s .= Html::el('input', array('type' => 'hidden', 'name' => urldecode($parts[0]), 'value' => urldecode($parts[1])));
}
$s = "\n\t" . $this->getWrapper('hidden container')->setHtml($s);
}
return $el->startTag() . $s;
} else {
return $this->form->getElementPrototype()->startTag();
}
}
btw: jak se palikuji patch? TurtoiseSVN mi stavkuje a nic nedela. Funguje jeste vubec SVN → jak dlouho jeste bude?