Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BRIC
dokuwiki
Commits
8f0df229
Commit
8f0df229
authored
9 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
Form: added Button element #1312
parent
08099e4f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
_test/tests/inc/form/buttonelement.test.php
+40
-0
40 additions, 0 deletions
_test/tests/inc/form/buttonelement.test.php
inc/Form/ButtonElement.php
+34
-0
34 additions, 0 deletions
inc/Form/ButtonElement.php
inc/Form/Form.php
+24
-0
24 additions, 0 deletions
inc/Form/Form.php
with
98 additions
and
0 deletions
_test/tests/inc/form/buttonelement.test.php
0 → 100644
+
40
−
0
View file @
8f0df229
<?php
use
dokuwiki\Form
;
class
form_buttonelement_test
extends
DokuWikiTest
{
function
test_simple
()
{
$form
=
new
Form\Form
();
$form
->
addButton
(
'foo'
,
'Hello <b>World</b>'
)
->
val
(
'bam'
)
->
attr
(
'type'
,
'submit'
);
$html
=
$form
->
toHTML
();
$pq
=
phpQuery
::
newDocumentXHTML
(
$html
);
$input
=
$pq
->
find
(
'button[name=foo]'
);
$this
->
assertTrue
(
$input
->
length
==
1
);
$this
->
assertEquals
(
'bam'
,
$input
->
val
());
$this
->
assertEquals
(
'submit'
,
$input
->
attr
(
'type'
));
$this
->
assertEquals
(
'Hello <b>World</b>'
,
$input
->
text
());
// tags were escaped
$b
=
$input
->
find
(
'b'
);
// no tags found
$this
->
assertTrue
(
$b
->
length
==
0
);
}
function
test_html
()
{
$form
=
new
Form\Form
();
$form
->
addButtonHTML
(
'foo'
,
'Hello <b>World</b>'
)
->
val
(
'bam'
)
->
attr
(
'type'
,
'submit'
);
$html
=
$form
->
toHTML
();
$pq
=
phpQuery
::
newDocumentXHTML
(
$html
);
$input
=
$pq
->
find
(
'button[name=foo]'
);
$this
->
assertTrue
(
$input
->
length
==
1
);
$this
->
assertEquals
(
'bam'
,
$input
->
val
());
$this
->
assertEquals
(
'submit'
,
$input
->
attr
(
'type'
));
$this
->
assertEquals
(
'Hello World'
,
$input
->
text
());
// tags are stripped here
$b
=
$input
->
find
(
'b'
);
// tags found
$this
->
assertTrue
(
$b
->
length
==
1
);
}
}
This diff is collapsed.
Click to expand it.
inc/Form/ButtonElement.php
0 → 100644
+
34
−
0
View file @
8f0df229
<?php
namespace
dokuwiki\Form
;
/**
* Class ButtonElement
*
* Represents a simple button
*
* @package dokuwiki\Form
*/
class
ButtonElement
extends
Element
{
/** @var string HTML content */
protected
$content
=
''
;
/**
* @param string $name
* @param string $content HTML content of the button. You have to escape it yourself.
*/
function
__construct
(
$name
,
$content
=
''
)
{
parent
::
__construct
(
'button'
,
array
(
'name'
=>
$name
,
'value'
=>
1
));
$this
->
content
=
$content
;
}
/**
* The HTML representation of this element
*
* @return string
*/
public
function
toHTML
()
{
return
'<button '
.
buildAttributes
(
$this
->
attrs
())
.
'>'
.
$this
->
content
.
'</button>'
;
}
}
This diff is collapsed.
Click to expand it.
inc/Form/Form.php
+
24
−
0
View file @
8f0df229
...
@@ -233,6 +233,30 @@ class Form extends Element {
...
@@ -233,6 +233,30 @@ class Form extends Element {
return
$this
->
addElement
(
new
TextareaElement
(
$name
,
$label
),
$pos
);
return
$this
->
addElement
(
new
TextareaElement
(
$name
,
$label
),
$pos
);
}
}
/**
* Adds a simple button, escapes the content for you
*
* @param string $name
* @param string $content
* @param int $pos
* @return Element
*/
public
function
addButton
(
$name
,
$content
,
$pos
=
-
1
)
{
return
$this
->
addElement
(
new
ButtonElement
(
$name
,
hsc
(
$content
)),
$pos
);
}
/**
* Adds a simple button, allows HTML for content
*
* @param string $name
* @param string $html
* @param int $pos
* @return Element
*/
public
function
addButtonHTML
(
$name
,
$html
,
$pos
=
-
1
)
{
return
$this
->
addElement
(
new
ButtonElement
(
$name
,
$html
),
$pos
);
}
/**
/**
* Add fixed HTML to the form
* Add fixed HTML to the form
*
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment