This repository was archived by the owner on Nov 27, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +51
-74
lines changed
src/AbaLookup/Form/View/Helper Expand file tree Collapse file tree 5 files changed +51
-74
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ public function getViewHelperConfig()
59
59
return [
60
60
'invokables ' => [
61
61
'anchor ' => 'AbaLookup\View\Helper\AnchorLink ' ,
62
+ 'form ' => 'AbaLookup\Form\View\Helper\Form ' ,
62
63
'scheduleHelper ' => 'AbaLookup\View\Helper\ScheduleHelper ' ,
63
64
'script ' => 'AbaLookup\View\Helper\Script ' ,
64
65
'stylesheet ' => 'AbaLookup\View\Helper\Stylesheet ' ,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace AbaLookup \Form \View \Helper ;
4
+
5
+ use
6
+ Zend \Form \FormInterface ,
7
+ Zend \Form \View \Helper \Form as ZendFormHelper
8
+ ;
9
+
10
+ /**
11
+ * View helper that generates a form
12
+ */
13
+ class Form extends ZendFormHelper
14
+ {
15
+ /**
16
+ * Returns the HTML markup for the given form
17
+ *
18
+ * @param FormInterface $f The form.
19
+ * @return string
20
+ */
21
+ public function markup (FormInterface $ f )
22
+ {
23
+ $ v = $ this ->getView ();
24
+ $ m = '' ;
25
+ $ m .= $ this ->openTag ($ f );
26
+ foreach ($ f as $ e ) {
27
+ $ t = $ e ->getAttribute ('type ' );
28
+ $ l = $ e ->getLabel ();
29
+ // To style checkboxes and radio buttons, the label needs to come after the element
30
+ // In all other cases, it is more semantic for the label to come before the element
31
+ $ content = ($ l && ($ t == 'checkbox ' || $ t == 'radio ' )) ?
32
+ ('<div class="checkbox"> ' . $ v ->formElement ($ e ) . $ v ->formLabel ($ e , $ l ) . '</div> ' ) :
33
+ (($ l ) ? ('' . $ v ->formLabel ($ e , $ l ) . $ v ->formElement ($ e )) : $ v ->formElement ($ e ));
34
+ $ m .= sprintf (
35
+ '<div class="row">
36
+ <div class="twelve columns">
37
+ %s
38
+ </div>
39
+ </div> ' ,
40
+ $ content
41
+ );
42
+ }
43
+ $ m .= $ this ->closeTag ();
44
+ return $ m ;
45
+ }
46
+ }
Original file line number Diff line number Diff line change 12
12
$ this ->form ->setAttribute ('class ' , 'left ' );
13
13
$ this ->form ->setAttribute ('action ' , '/users/login ' );
14
14
$ this ->form ->setAttribute ('method ' , 'post ' );
15
- echo $ this ->form ()->openTag ($ this ->form );
16
- foreach ($ this ->form as $ element ) {
17
- ?>
18
- <div class="row">
19
- <div class="twelve columns">
20
- <?php
21
- // To style checkboxes and radio buttons, the label needs to come after the element
22
- // In all other cases, it is more semantic for the label to come before the element
23
- $ type = $ element ->getAttribute ('type ' );
24
- $ label = $ element ->getLabel ();
25
- if ($ label && ($ type == 'checkbox ' || $ type == 'radio ' )) {
26
- echo $ this ->formElement ($ element );
27
- echo $ this ->formLabel ($ element , $ label );
28
- } elseif ($ label ) {
29
- echo $ this ->formLabel ($ element , $ label );
30
- echo $ this ->formElement ($ element );
31
- } else {
32
- echo $ this ->formElement ($ element ); // There is no label
33
- }
34
- ?>
35
- </div>
36
- </div>
37
- <?php
38
- }
39
- echo $ this ->form ()->closeTag ();
15
+ echo $ this ->form ()->markup ($ this ->form );
40
16
?>
41
17
</div>
42
18
<aside class="aside four columns">
Original file line number Diff line number Diff line change 10
10
$ this ->form ->setAttribute ('class ' , 'left ' );
11
11
$ this ->form ->setAttribute ('action ' , '/users ' . '/ ' . $ this ->user ->getId () . '/profile/edit ' );
12
12
$ this ->form ->setAttribute ('method ' , 'post ' );
13
- echo $ this ->form ()->openTag ($ this ->form );
14
-
15
- foreach ($ this ->form as $ element ) {
16
- ?>
17
- <div class="row">
18
- <div class="twelve columns">
19
- <?php
20
- $ label = $ element ->getLabel ();
21
- if ($ label ) {
22
- echo $ this ->formLabel ($ element , $ label );
23
- }
24
- echo $ this ->formElement ($ element );
25
- ?>
26
- </div>
27
- </div>
28
- <?php
29
- }
30
-
31
- echo $ this ->form ()->closeTag ();
13
+ echo $ this ->form ()->markup ($ this ->form );
32
14
?>
33
15
</div>
34
16
<aside class="aside four columns">
35
17
<h3>Details</h3>
36
- <p>
37
- Edit your profile information.
38
- </p>
18
+ <p>Edit your profile information.</p>
39
19
</aside>
Original file line number Diff line number Diff line change 16
16
$ this ->form ->setAttribute ('class ' , 'left ' );
17
17
$ this ->form ->setAttribute ('action ' , sprintf ('/users/register/%s ' , $ this ->type ));
18
18
$ this ->form ->setAttribute ('method ' , 'post ' );
19
- echo $ this ->form ()->openTag ($ this ->form );
20
- foreach ($ this ->form as $ element ) {
21
- ?>
22
- <div class="row">
23
- <div class="twelve columns">
24
- <?php
25
- // To style checkboxes and radio buttons, the label needs to come after the element
26
- // In all other cases, it is more semantic for the label to come before the element
27
- $ type = $ element ->getAttribute ('type ' );
28
- $ label = $ element ->getLabel ();
29
- if ($ label && ($ type == 'checkbox ' || $ type == 'radio ' )) {
30
- echo '<div class="checkbox"> ' ;
31
- echo $ this ->formElement ($ element );
32
- echo $ this ->formLabel ($ element , $ label );
33
- echo '</div> ' ;
34
- } elseif ($ label ) {
35
- echo $ this ->formLabel ($ element , $ label );
36
- echo $ this ->formElement ($ element );
37
- } else {
38
- echo $ this ->formElement ($ element ); // There is no label
39
- }
40
- ?>
41
- </div>
42
- </div>
43
- <?php
44
- }
45
- echo $ this ->form ()->closeTag ();
19
+ echo $ this ->form ()->markup ($ this ->form );
46
20
?>
47
21
</div>
You can’t perform that action at this time.
0 commit comments