From 3cd1d0821e83cb2c6a36fafe14dc37ce2ecbf6fa Mon Sep 17 00:00:00 2001 From: KoKsPfLaNzE Date: Sat, 7 Nov 2015 23:16:57 +0100 Subject: [PATCH] required marker added in form label --- src/PServerCMS/Form/AddEmail.php | 6 ++-- src/PServerCMS/Form/ChangePwd.php | 3 ++ src/PServerCMS/Form/Password.php | 6 ++-- src/PServerCMS/Form/PwLost.php | 6 ++-- src/PServerCMS/Form/Register.php | 22 +++++++++---- src/PServerCMS/Module.php | 3 +- src/PServerCMS/View/Helper/FormLabel.php | 41 ++++++++++++++++++++++++ 7 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 src/PServerCMS/View/Helper/FormLabel.php diff --git a/src/PServerCMS/Form/AddEmail.php b/src/PServerCMS/Form/AddEmail.php index 61a3392..8d0d197 100644 --- a/src/PServerCMS/Form/AddEmail.php +++ b/src/PServerCMS/Form/AddEmail.php @@ -31,7 +31,8 @@ public function __construct() 'attributes' => [ 'placeholder' => 'Email', 'class' => 'form-control', - 'type' => 'email' + 'type' => 'email', + 'required' => true, ], ]); $this->add([ @@ -42,7 +43,8 @@ public function __construct() 'attributes' => [ 'placeholder' => 'Email Verify', 'class' => 'form-control', - 'type' => 'email' + 'type' => 'email', + 'required' => true, ], ]); diff --git a/src/PServerCMS/Form/ChangePwd.php b/src/PServerCMS/Form/ChangePwd.php index 45bfeb2..a55a209 100644 --- a/src/PServerCMS/Form/ChangePwd.php +++ b/src/PServerCMS/Form/ChangePwd.php @@ -23,6 +23,7 @@ public function __construct() 'class' => 'form-control', 'type' => 'password', 'placeholder' => 'Current Web Password', + 'required' => true, ], ]); @@ -32,6 +33,7 @@ public function __construct() 'class' => 'form-control', 'type' => 'password', 'placeholder' => 'New Password', + 'required' => true, ], ]); @@ -41,6 +43,7 @@ public function __construct() 'class' => 'form-control', 'type' => 'password', 'placeholder' => 'Confirm new Password', + 'required' => true, ], ]); diff --git a/src/PServerCMS/Form/Password.php b/src/PServerCMS/Form/Password.php index f6effe3..5535788 100644 --- a/src/PServerCMS/Form/Password.php +++ b/src/PServerCMS/Form/Password.php @@ -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, ], ]); @@ -104,7 +105,8 @@ public function addSecretQuestion(UserInterface $user) 'attributes' => [ 'placeholder' => 'Answer', 'class' => 'form-control', - 'type' => 'text' + 'type' => 'text', + 'required' => true, ], ]); diff --git a/src/PServerCMS/Form/PwLost.php b/src/PServerCMS/Form/PwLost.php index 9d1f2d1..be791af 100644 --- a/src/PServerCMS/Form/PwLost.php +++ b/src/PServerCMS/Form/PwLost.php @@ -26,7 +26,8 @@ public function __construct(ServiceLocatorInterface $sm) ], 'attributes' => [ 'class' => 'form-control', - 'type' => 'text' + 'type' => 'text', + 'required' => true, ], ]); @@ -37,7 +38,8 @@ public function __construct(ServiceLocatorInterface $sm) ]) ->setAttributes([ 'class' => 'form-control', - 'type' => 'text' + 'type' => 'text', + 'required' => true, ]); $this->add($captcha); diff --git a/src/PServerCMS/Form/Register.php b/src/PServerCMS/Form/Register.php index 71a636b..6876255 100644 --- a/src/PServerCMS/Form/Register.php +++ b/src/PServerCMS/Form/Register.php @@ -31,7 +31,8 @@ public function __construct(ServiceLocatorInterface $sm) 'attributes' => [ 'placeholder' => 'Username', 'class' => 'form-control', - 'type' => 'text' + 'type' => 'text', + 'required' => true, ], ]); @@ -43,7 +44,8 @@ public function __construct(ServiceLocatorInterface $sm) 'attributes' => [ 'placeholder' => 'Email', 'class' => 'form-control', - 'type' => 'email' + 'type' => 'email', + 'required' => true, ], ]); $this->add([ @@ -54,7 +56,8 @@ public function __construct(ServiceLocatorInterface $sm) 'attributes' => [ 'placeholder' => 'Email Verify', 'class' => 'form-control', - 'type' => 'email' + 'type' => 'email', + 'required' => true, ], ]); @@ -66,7 +69,8 @@ public function __construct(ServiceLocatorInterface $sm) 'attributes' => [ 'placeholder' => 'Password', 'class' => 'form-control', - 'type' => 'password' + 'type' => 'password', + 'required' => true, ], ]); @@ -78,7 +82,8 @@ public function __construct(ServiceLocatorInterface $sm) 'attributes' => [ 'placeholder' => 'Password Verify', 'class' => 'form-control', - 'type' => 'password' + 'type' => 'password', + 'required' => true, ], ]); @@ -105,6 +110,7 @@ public function __construct(ServiceLocatorInterface $sm) ], 'attributes' => [ 'class' => 'form-control', + 'required' => true, ], ]); @@ -116,7 +122,8 @@ public function __construct(ServiceLocatorInterface $sm) 'attributes' => [ 'placeholder' => 'Answer', 'class' => 'form-control', - 'type' => 'text' + 'type' => 'text', + 'required' => true, ], ]); } @@ -128,7 +135,8 @@ public function __construct(ServiceLocatorInterface $sm) ]) ->setAttributes([ 'class' => 'form-control', - 'type' => 'text' + 'type' => 'text', + 'required' => true, ]); $this->add($captcha, [ diff --git a/src/PServerCMS/Module.php b/src/PServerCMS/Module.php index bee6cbf..2c4d36d 100644 --- a/src/PServerCMS/Module.php +++ b/src/PServerCMS/Module.php @@ -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) { diff --git a/src/PServerCMS/View/Helper/FormLabel.php b/src/PServerCMS/View/Helper/FormLabel.php new file mode 100644 index 0000000..4e93cd6 --- /dev/null +++ b/src/PServerCMS/View/Helper/FormLabel.php @@ -0,0 +1,41 @@ +element = $element; + + return parent::__invoke($element, $labelContent, $position); + } + + /** + * Return a closing label tag + * + * @return string + */ + public function closeTag() + { + $result = ''; + if ($this->element->hasAttribute('required') && $this->element->getAttribute('required')) { + $result = sprintf('* %s', $result); + } + + return $result; + } +} \ No newline at end of file