Skip to content
Snippets Groups Projects
Unverified Commit 7fa270bc authored by Michael Große's avatar Michael Große
Browse files

feat(Form): add parameter to omit security token in forms

This is useful for anonymously useable forms, like the search.
parent 3286c65d
No related branches found
No related tags found
No related merge requests found
......@@ -24,8 +24,9 @@ class Form extends Element {
* Creates a new, empty form with some default attributes
*
* @param array $attributes
* @param bool $unsafe if true, then the security token is ommited
*/
public function __construct($attributes = array()) {
public function __construct($attributes = array(), $unsafe = false) {
global $ID;
parent::__construct('form', $attributes);
......@@ -49,7 +50,9 @@ class Form extends Element {
}
// add the security token by default
$this->setHiddenField('sectok', getSecurityToken());
if (!$unsafe) {
$this->setHiddenField('sectok', getSecurityToken());
}
// identify this as a new form based form in HTML
$this->addClass('doku_form');
......
......@@ -65,7 +65,7 @@ class Search extends Ui
{
global $lang, $ID, $INPUT;
$searchForm = (new Form())->attrs(['method' => 'get'])->addClass('search-results-form');
$searchForm = (new Form(['method' => 'get'], true))->addClass('search-results-form');
$searchForm->setHiddenField('do', 'search');
$searchForm->setHiddenField('id', $ID);
$searchForm->setHiddenField('sf', '1');
......
......@@ -667,7 +667,7 @@ function tpl_searchform($ajax = true, $autocomplete = true) {
'role' => 'search',
'class' => 'search',
'id' => 'dw__search',
]);
], true);
$searchForm->addTagOpen('div')->addClass('no');
$searchForm->setHiddenField('do', 'search');
$searchForm->setHiddenField('id', $ID);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment