1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92:
<?php
namespace Nethgui\Widget\Xhtml;
class Form extends Panel implements \Nethgui\Utility\SessionConsumerInterface
{
protected function renderContent()
{
if ( ! $this->hasAttribute('name')) {
$this->setAttribute('name', 'FormAction');
}
$name = $this->getAttribute('name');
if (isset($this->view[$name])) {
$action = $this->view[$name];
} else {
$action = $this->view->getModuleUrl($this->getAttribute('action', ''));
}
if ( ! $this->hasAttribute('enctype') && $this->getAttribute('flags') & \Nethgui\Renderer\WidgetFactoryInterface::FORM_ENC_MULTIPART) {
$this->setAttribute('enctype', 'multipart/form-data');
};
$this->getRenderer()->rejectFlag(\Nethgui\Renderer\WidgetFactoryInterface::INSET_FORM);
$attributes = array(
'method' => $this->getAttribute('method', 'post'),
'action' => $action,
'class' => 'Form ' . $this->getClientEventTarget(),
'enctype' => $this->getAttribute('enctype', 'application/x-www-form-urlencoded'),
);
$this->setAttribute('tag', $this->getAttribute('tag', FALSE));
$security = $this->session->retrieve('SECURITY');
$content = '';
$content .= $this->openTag('form', $attributes);
$content .= parent::renderContent();
if(isset($security['csrfToken'])) {
$content .= $this->controlTag('input', 'csrfToken', 0, '', array(
'class' => FALSE,
'id' => FALSE,
'name' => 'csrfToken',
'type' => 'hidden',
'value' => $security['csrfToken'])
);
}
$content .= $this->closeTag('form');
return $content;
}
public function setSession(\Nethgui\Utility\SessionInterface $session)
{
$this->session = $session;
return $this;
}
}