Переглянути джерело

Add more html5 validation

https://caniuse.com/?search=user-invalid
https://caniuse.com/?search=minlength
Visman 2 роки тому
батько
коміт
1000a97430

+ 4 - 2
app/Models/Pages/Admin/Users/NewUser.php

@@ -96,6 +96,7 @@ class NewUser extends Users
                         'username' => [
                             'autofocus' => true,
                             'type'      => 'text',
+                            'minlength' => $this->c->USERNAME['min'],
                             'maxlength' => $this->user->isAdmin ? '190' : $this->c->USERNAME['max'],
                             'value'     => $data['username'] ?? null,
                             'caption'   => 'Username',
@@ -110,7 +111,7 @@ class NewUser extends Users
                             'caption'        => 'Email',
                             'help'           => 'Email help',
                             'required'       => true,
-                            'pattern'        => '.+@.+',
+                            'pattern'        => '^.*[^@]@[^@].*$',
                             'autocapitalize' => 'off',
                         ],
                         'password' => [
@@ -118,7 +119,8 @@ class NewUser extends Users
                             'caption'   => 'Passphrase',
                             'help'      => 'Passphrase help',
                             'required'  => true,
-                            'pattern'   => '^.{16,}$',
+                            'minlength' => '16',
+                            'pattern'   => '^.*[^ ] [^ ].*$',
                         ],
                     ],
                 ],

+ 1 - 0
app/Models/Pages/Profile/Edit.php

@@ -242,6 +242,7 @@ class Edit extends Profile
         if ($this->rules->rename) {
             $fields['username'] = [
                 'type'      => 'text',
+                'minlength' => $this->c->USERNAME['min'],
                 'maxlength' => $this->user->isAdmin ? '190' : $this->c->USERNAME['max'],
                 'caption'   => 'Username',
                 'required'  => true,

+ 1 - 1
app/Models/Pages/Profile/Email.php

@@ -231,7 +231,7 @@ class Email extends Profile
                             'maxlength'      => (string) $this->c->MAX_EMAIL_LENGTH,
                             'caption'        => $this->rules->confirmEmail ? 'New or old email' : 'New email',
                             'required'       => true,
-                            'pattern'        => '.+@.+',
+                            'pattern'        => '^.*[^@]@[^@].*$',
                             'value'          => $this->curUser->email,
                             'help'           => $this->rules->my ? 'Email instructions' : null,
                             'autocapitalize' => 'off',

+ 2 - 1
app/Models/Pages/Profile/Pass.php

@@ -108,7 +108,8 @@ class Pass extends Profile
                             'type'      => 'password',
                             'caption'   => 'New pass',
                             'required'  => true,
-                            'pattern'   => '^.{16,}$',
+                            'minlength' => '16',
+                            'pattern'   => '^.*[^ ] [^ ].*$',
                             'help'      => 'Passphrase help',
                         ],
                         'password' => [

+ 4 - 2
app/Models/Pages/Register.php

@@ -179,7 +179,7 @@ class Register extends Page
                 'caption'        => 'Email',
                 'help'           => 1 === $this->c->config->b_regs_verify ? 'Email help2' : 'Email help',
                 'required'       => true,
-                'pattern'        => '.+@.+',
+                'pattern'        => '^.*[^@]@[^@].*$',
                 'autocapitalize' => 'off',
             ];
         }
@@ -187,6 +187,7 @@ class Register extends Page
         $fields['username'] = [
             'class'     => ['hint'],
             'type'      => 'text',
+            'minlength' => $this->c->USERNAME['min'],
             'maxlength' => $this->c->USERNAME['max'],
             'value'     => $v->username ?? ($this->useOAuth ? $this->nameGenerator($this->provider) : ''),
             'caption'   => 'Username',
@@ -202,7 +203,8 @@ class Register extends Page
                 'caption'   => 'Passphrase',
                 'help'      => 'Passphrase help',
                 'required'  => true,
-                'pattern'   => '^.{16,}$',
+                'minlength' => '16',
+                'pattern'   => '^.*[^ ] [^ ].*$',
             ];
         }
 

+ 2 - 0
app/Models/Pages/Search.php

@@ -171,6 +171,7 @@ class Search extends Page
                         'keywords' => [
                             'class'     => ['w0'],
                             'type'      => 'text',
+                            'minlength' => '3',
                             'maxlength' => '100',
                             'caption'   => 'Keyword search',
                             'value'     => $v->keywords ?? '',
@@ -209,6 +210,7 @@ class Search extends Page
                         'keywords' => [
                             'class'     => ['w2'],
                             'type'      => 'text',
+                            'minlength' => '3',
                             'maxlength' => '100',
                             'caption'   => 'Keyword search',
                             'value'     => $v->keywords ?? '',

+ 1 - 1
app/templates/layouts/form.forkbb.php

@@ -36,7 +36,7 @@
                         @case ('number')
                         @case ('password')
                         @case ('file')
-                <input id="id-{{ $key }}" name="{{ $key }}" class="f-ctrl" type="{{ $cur['type'] }}" @foreach ($cur as $k => $v) @if (\in_array($k, ['autofocus', 'disabled', 'multiple', 'readonly', 'required'], true) && ! empty($v)) {!! $k !!} @elseif (\in_array($k, ['accept', 'autocapitalize', 'autocomplete', 'max', 'maxlength', 'min', 'pattern', 'placeholder', 'step', 'title', 'value'], true)) {!! $k !!}="{{ $v }}" @endif @endforeach>
+                <input id="id-{{ $key }}" name="{{ $key }}" class="f-ctrl" type="{{ $cur['type'] }}" @foreach ($cur as $k => $v) @if (\in_array($k, ['autofocus', 'disabled', 'multiple', 'readonly', 'required'], true) && ! empty($v)) {!! $k !!} @elseif (\in_array($k, ['accept', 'autocapitalize', 'autocomplete', 'max', 'maxlength', 'min', 'minlength', 'pattern', 'placeholder', 'step', 'title', 'value'], true)) {!! $k !!}="{{ $v }}" @endif @endforeach>
                             @break
                         @case ('textarea')
                 <textarea id="id-{{ $key }}" name="{{ $key }}" class="f-ctrl f-ytxtarea" @foreach ($cur as $k => $v) @if (\in_array($k, ['autofocus', 'disabled', 'readonly', 'required'], true) && ! empty($v)) {!! $k !!} @elseif (\in_array($k, ['maxlength', 'placeholder', 'rows', 'title'], true)) {!! $k !!}="{{ $v }}" @elseif ('data' === $k) @foreach ($v as $kd => $vd) data-{{ $kd }}="{{ $vd }}" @endforeach @endif @endforeach>{{ $cur['value'] or '' }}</textarea>

+ 4 - 0
public/style/ForkBB/style.css

@@ -819,6 +819,10 @@ body,
   border: 0.0625rem solid #AA7939;
 }
 
+#fork input.f-ctrl:user-invalid {
+  border: 0.125rem dotted red;
+}
+
 #fork input:focus,
 #fork select:focus,
 #fork textarea:focus {