Archived
1
0
Fork 0

Style fixes.

This commit is contained in:
Henrik Hautakoski 2023-04-30 16:52:38 +02:00
parent a7a59b690a
commit be4950ff88
43 changed files with 187 additions and 149 deletions

View file

@ -7,12 +7,14 @@ use Phalcon\Forms\Form;
/**
* Element types
*/
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Submit;
/**
* Validators
*/
use Phalcon\Validation\Validator\StringLength;
class CallbackCreate extends Form

View file

@ -7,6 +7,7 @@ use Phalcon\Forms\Form;
/**
* Element types
*/
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Password;
use Phalcon\Forms\Element\Submit;
@ -14,6 +15,7 @@ use Phalcon\Forms\Element\Submit;
/**
* Validators
*/
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Email as EmailValidator;
use Phalcon\Validation\Validator\StringLength;

View file

@ -5,16 +5,19 @@ namespace App\Form;
/**
* Models
*/
use App\Model\Data\User;
/**
* Phalcon Form
*/
use Httpcb\Form as FormBase;
/**
* Element types
*/
use Phalcon\Forms\Element\Text,
Phalcon\Forms\Element\Password,
Phalcon\Forms\Element\Submit;
@ -22,6 +25,7 @@ use Phalcon\Forms\Element\Text,
/**
* Validators
*/
use Phalcon\Validation,
Phalcon\Validation\Validator\Callback as CallbackValidator,
Phalcon\Validation\Validator\Alnum as AlnumValidator,
@ -54,7 +58,9 @@ class Registration extends FormBase
'messageMinimum' => 'Username must be at least :min characters long.',
]),
new CallbackValidator([
'callback' => function($data) { return User::findFirstByUsername($data['username']) === false; },
'callback' => function ($data) {
return User::findFirstByUsername($data['username']) === false;
},
'message' => 'The username already exists.',
'attribute' => 'username',
])
@ -63,7 +69,7 @@ class Registration extends FormBase
$this->add($username);
// Names
foreach([ 'first-name' => 'Firstname', 'last-name' => 'Lastname' ] as $id => $label) {
foreach (['first-name' => 'Firstname', 'last-name' => 'Lastname'] as $id => $label) {
$name = new Text($id, array(
'class' => 'form-control',
@ -87,7 +93,9 @@ class Registration extends FormBase
$email->addValidators([
new CallbackValidator([
'callback' => function($data) { return User::findFirstByEmail($data['email']) === false; },
'callback' => function ($data) {
return User::findFirstByEmail($data['email']) === false;
},
'message' => 'This email already exist.',
])
]);

View file

@ -5,16 +5,19 @@ namespace App\Form;
/**
* Models
*/
use App\Model\Data\User as UserModel;
/**
* Form
*/
use Httpcb\Form as FormBase;
/**
* Element types
*/
use Phalcon\Forms\Element\Text,
Phalcon\Forms\Element\Password,
Phalcon\Forms\Element\Submit;
@ -22,6 +25,7 @@ use Phalcon\Forms\Element\Text,
/**
* Validators
*/
use Phalcon\Validation\Validator\Callback as CallbackValidator,
Phalcon\Validation\Validator\Uniqueness as UniquenessValidator,
Phalcon\Validation\Validator\Alnum as AlnumValidator,
@ -56,15 +60,15 @@ class UserSettings extends FormBase
// Id
if ($entity && $entity->getId()) {
$id = new Text('id', array(
'class' => 'form-control',
'readonly' => '',
'disabled' => 'disabled',
));
$id = new Text('id', array(
'class' => 'form-control',
'readonly' => '',
'disabled' => 'disabled',
));
$id->addValidator(new IdenticalValidator([
'accepted' => $entity->getId(),
'allowEmpty' => true
'allowEmpty' => true
]));
$id->setLabel('ID');
@ -86,7 +90,7 @@ class UserSettings extends FormBase
);
if ($entity && strlen($entity->getUsername())) {
$validator_options['except'] = [ $entity->getUsername() ];
$validator_options['except'] = [$entity->getUsername()];
}
$username->addValidators([
@ -116,12 +120,12 @@ class UserSettings extends FormBase
'class' => 'form-control',
'placeholder' => 'Email',
'readonly' => '',
'disabled' => 'disabled',
'disabled' => 'disabled',
));
$email->addValidator(new IdenticalValidator([
'accepted' => $entity->getEmail(),
'allowEmpty' => true
'allowEmpty' => true
]));
} else {
$email = new Text('email', array(
@ -136,7 +140,7 @@ class UserSettings extends FormBase
];
if ($entity && strlen($entity->getEmail())) {
$validator_options['except'] = [ $entity->getEmail() ];
$validator_options['except'] = [$entity->getEmail()];
}
$email->addValidators([
@ -191,7 +195,7 @@ class UserSettings extends FormBase
if ($this->_admin === false && $entity && strlen($entity->getPassword()) > 0) {
$validation->add('passwordCurrent', new CallbackValidator([
'callback' => function($data) {
'callback' => function ($data) {
$new_pw = $data['passwordNew'];
if (strlen($new_pw) > 0) {
$value = $data['passwordCurrent'];