function onOpen() { $this->removeAll(); $key = $this->getAttribute('name'); $fld = $this->getDocument()->getVariable($key); $this->setName('input'); if($fld instanceof TextInputField) { if($fld->getType() == TextInputField::TEXTAREA) { $this->setName('textarea'); $this->addNode(new HTMLTextNode($this, htmlSpecialChars($fld->getValue(), ENT_QUOTES, 'UTF-8'))); } else { $this->setAttribute('type', $fld->getType() == TextInputField::TEXT ? 'text' : 'password'); $this->setAttribute('value', htmlSpecialChars($fld->getValue(), ENT_QUOTES, 'UTF-8')); // $this->setAttribute('value', $fld->getValue()); } } elseif($fld instanceof CheckBoxInputField) { $this->setAttribute('type', 'checkbox'); $this->setAttribute('value', '1'); if($fld->getValue()) { $this->setAttribute('checked', 'true'); } $t = new HTMLTag($this, 'input', array()); $t->setAttribute('value', ''); $t->setAttribute('type', 'hidden'); $t->setAttribute('name', $key); $this->getDocument()->process($t); } elseif($fld instanceof SelectInputField) { $this->setName('select'); $this->setAttribute('size', '1'); if($e = $fld->getEmpty()) { $t = new HTMLTag($this, 'option', array()); $t->setAttribute('value', ''); $t->addNode($tn = new HTMLTextNode($this, htmlSpecialChars($e, ENT_QUOTES, 'UTF-8'))); $this->addNode($t); } foreach($fld->getData() as $k=>$v) { $t = new HTMLTag($this, 'option', array()); $t->setAttribute('value', htmlSpecialChars($k, ENT_QUOTES, 'UTF-8')); if($fld->getValue() == $k) { $t->setAttribute('selected', 'true'); } $t->addNode($tn = new HTMLTextNode($this, $v)); $this->addNode($t); } } elseif($fld instanceof UploadFileInputField) { $this->setAttribute('type', 'file'); } elseif($fld instanceof RadioButtonInputField) { $this->setAttribute('type', 'radio'); $this->setAttribute('value', htmlSpecialChars($v = $fld->getNextValue(), ENT_QUOTES, 'UTF-8')); if($v == $fld->getValue()) { $this->setAttribute('checked', 'true'); } } else { return self::SKIP_BODY; } return self::PROCESS_BODY; }
function onOpen() { $this->wml = $this->getDocument() instanceof WMLDocument; if(!$this->key) { $this->key = $this->getAttribute('key'); $this->removeAttribute('key'); } $this->form = $this->getDocument()->getVariable($this->key); if(is_null($this->form)) { return self::SKIP_BODY; } $this->parameters = new HTMLTag($this, 'div', array()); $this->parameters->setExposed(false); if($this->ifError = $this->getTagByName('iferror')) { $this->ifError->setExposed(false); } if($this->ifInputErrors = $this->getTagByName('ifinputerrors')) { $this->ifInputErrors->setExposed(false); } if($this->wml) { $this->setName('fieldset'); $this->action->name = 'postfield'; $do = new HTMLTag($this, 'do', array()); $do->setAttribute('type', 'Accept'); $go = new HTMLTag($this, 'go', array()); $go->setAttribute('href', '?'); $go->setAttribute('method', $this->form->getMethod() == Request::METHOD_POST ? 'post' : 'get'); $go->addNode($this->parameters); $do->addNode($go); $this->addNode($do); } else { $this->setAttribute('method', $this->form->getMethod() == Request::METHOD_POST ? 'post' : 'get'); if($this->getAttribute('method') == 'post') { $this->setAttribute('enctype', 'multipart/form-data'); } $this->setName('form'); $this->setAttribute('action', htmlSpecialChars(Request::$URL, ENT_QUOTES, 'UTF-8')); // Set the HTML4.01 attribute accept-encoding if we generate 4.01 HTML pages // !!! Must use version_compare !!! if(Package::getPackage($this)->getProperty('html.version') == '4.01') { $this->setAttribute('accept-charset', 'UTF-8'); } $this->addNode($this->parameters); } // Pass over parameters $pars = $this->form->getParameters(); if($this->wml) { foreach(array_keys($this->form->getFields()) as $fname) { $pars[$fname] = '$(' . $fname . ')'; } } $pars['action'] = $this->form->getLocation()->getAction(); foreach($pars as $k=>$v) { $a = new HTMLTag($this, $this->wml ? 'postfield' : 'input', array()); $a->setAttribute('name', htmlSpecialChars($k, ENT_QUOTES, 'UTF-8')); $a->setAttribute('value', htmlSpecialChars($v, ENT_QUOTES, 'UTF-8')); if(!$this->wml) { $a->setAttribute('type', 'hidden'); } $this->parameters->addNode($a); } if($this->ifInputErrors) { $this->ifInputErrors->setEnabled( $this->form->isSubmitted() && !$this->form->isValid()); } return self::PROCESS_BODY; }