Skip to content

Commit

Permalink
required marker added in form label
Browse files Browse the repository at this point in the history
  • Loading branch information
kokspflanze committed Nov 7, 2015
1 parent a70f25b commit 3cd1d08
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/PServerCMS/Form/AddEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function __construct()
'attributes' => [
'placeholder' => 'Email',
'class' => 'form-control',
'type' => 'email'
'type' => 'email',
'required' => true,
],
]);
$this->add([
Expand All @@ -42,7 +43,8 @@ public function __construct()
'attributes' => [
'placeholder' => 'Email Verify',
'class' => 'form-control',
'type' => 'email'
'type' => 'email',
'required' => true,
],
]);

Expand Down
3 changes: 3 additions & 0 deletions src/PServerCMS/Form/ChangePwd.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct()
'class' => 'form-control',
'type' => 'password',
'placeholder' => 'Current Web Password',
'required' => true,
],
]);

Expand All @@ -32,6 +33,7 @@ public function __construct()
'class' => 'form-control',
'type' => 'password',
'placeholder' => 'New Password',
'required' => true,
],
]);

Expand All @@ -41,6 +43,7 @@ public function __construct()
'class' => 'form-control',
'type' => 'password',
'placeholder' => 'Confirm new Password',
'required' => true,
],
]);

Expand Down
6 changes: 4 additions & 2 deletions src/PServerCMS/Form/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public function addSecretQuestion(UserInterface $user)
'class' => 'form-control',
'type' => 'text',
'disabled' => 'true',
'value' => $answer->getQuestion()->getQuestion()
'value' => $answer->getQuestion()->getQuestion(),
'required' => true,
],
]);

Expand All @@ -104,7 +105,8 @@ public function addSecretQuestion(UserInterface $user)
'attributes' => [
'placeholder' => 'Answer',
'class' => 'form-control',
'type' => 'text'
'type' => 'text',
'required' => true,
],
]);

Expand Down
6 changes: 4 additions & 2 deletions src/PServerCMS/Form/PwLost.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function __construct(ServiceLocatorInterface $sm)
],
'attributes' => [
'class' => 'form-control',
'type' => 'text'
'type' => 'text',
'required' => true,
],
]);

Expand All @@ -37,7 +38,8 @@ public function __construct(ServiceLocatorInterface $sm)
])
->setAttributes([
'class' => 'form-control',
'type' => 'text'
'type' => 'text',
'required' => true,
]);
$this->add($captcha);

Expand Down
22 changes: 15 additions & 7 deletions src/PServerCMS/Form/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function __construct(ServiceLocatorInterface $sm)
'attributes' => [
'placeholder' => 'Username',
'class' => 'form-control',
'type' => 'text'
'type' => 'text',
'required' => true,
],
]);

Expand All @@ -43,7 +44,8 @@ public function __construct(ServiceLocatorInterface $sm)
'attributes' => [
'placeholder' => 'Email',
'class' => 'form-control',
'type' => 'email'
'type' => 'email',
'required' => true,
],
]);
$this->add([
Expand All @@ -54,7 +56,8 @@ public function __construct(ServiceLocatorInterface $sm)
'attributes' => [
'placeholder' => 'Email Verify',
'class' => 'form-control',
'type' => 'email'
'type' => 'email',
'required' => true,
],
]);

Expand All @@ -66,7 +69,8 @@ public function __construct(ServiceLocatorInterface $sm)
'attributes' => [
'placeholder' => 'Password',
'class' => 'form-control',
'type' => 'password'
'type' => 'password',
'required' => true,
],
]);

Expand All @@ -78,7 +82,8 @@ public function __construct(ServiceLocatorInterface $sm)
'attributes' => [
'placeholder' => 'Password Verify',
'class' => 'form-control',
'type' => 'password'
'type' => 'password',
'required' => true,
],
]);

Expand All @@ -105,6 +110,7 @@ public function __construct(ServiceLocatorInterface $sm)
],
'attributes' => [
'class' => 'form-control',
'required' => true,
],
]);

Expand All @@ -116,7 +122,8 @@ public function __construct(ServiceLocatorInterface $sm)
'attributes' => [
'placeholder' => 'Answer',
'class' => 'form-control',
'type' => 'text'
'type' => 'text',
'required' => true,
],
]);
}
Expand All @@ -128,7 +135,8 @@ public function __construct(ServiceLocatorInterface $sm)
])
->setAttributes([
'class' => 'form-control',
'type' => 'text'
'type' => 'text',
'required' => true,
]);

$this->add($captcha, [
Expand Down
3 changes: 2 additions & 1 deletion src/PServerCMS/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function getViewHelperConfig()
{
return [
'invokables' => [
'pserverformerrors' => 'PServerCMS\View\Helper\FormError'
'pserverformerrors' => 'PServerCMS\View\Helper\FormError',
'formlabel' => 'PServerCMS\View\Helper\FormLabel',
],
'factories' => [
'sidebarWidget' => function (AbstractPluginManager $pluginManager) {
Expand Down
41 changes: 41 additions & 0 deletions src/PServerCMS/View/Helper/FormLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php


namespace PServerCMS\View\Helper;

use Zend\Form\ElementInterface;
use Zend\Form\View\Helper\FormLabel as OriginalFormLabel;

class FormLabel extends OriginalFormLabel
{
/** @var ElementInterface */
protected $element;

/**
* @param ElementInterface|null $element
* @param null $labelContent
* @param null $position
* @return string|OriginalFormLabel
*/
public function __invoke(ElementInterface $element = null, $labelContent = null, $position = null)
{
$this->element = $element;

return parent::__invoke($element, $labelContent, $position);
}

/**
* Return a closing label tag
*
* @return string
*/
public function closeTag()
{
$result = '</label>';
if ($this->element->hasAttribute('required') && $this->element->getAttribute('required')) {
$result = sprintf('<span class="required-mark">*</span> %s', $result);
}

return $result;
}
}

0 comments on commit 3cd1d08

Please sign in to comment.