mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Merge pull request #4046 from mryoaz/contactform-fix
Fix Contactform UX and validation (fixes #2239 and #2240)
This commit is contained in:
commit
61987da3ea
3 changed files with 37 additions and 2 deletions
|
@ -6,6 +6,7 @@ use Illuminate\Http\Request;
|
|||
use Auth;
|
||||
use App\Contact;
|
||||
use App\Jobs\ContactPipeline\ContactPipeline;
|
||||
use App\Rules\MaxMultiLine;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
|
@ -21,7 +22,7 @@ class ContactController extends Controller
|
|||
abort_if(!Auth::check(), 403);
|
||||
|
||||
$this->validate($request, [
|
||||
'message' => 'required|string|min:5|max:500',
|
||||
'message' => ['required', 'string', 'min:5', new MaxMultiLine('500')],
|
||||
'request_response' => 'string|max:3'
|
||||
]);
|
||||
|
||||
|
|
34
app/Rules/MaxMultiLine.php
Normal file
34
app/Rules/MaxMultiLine.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Contracts\Validation\InvokableRule;
|
||||
|
||||
class MaxMultiLine implements InvokableRule
|
||||
{
|
||||
private $maxCharacters;
|
||||
|
||||
public function __construct($maxCharacters)
|
||||
{
|
||||
$this->maxCharacters = $maxCharacters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
* @return void
|
||||
*/
|
||||
public function __invoke($attribute, $value, $fail)
|
||||
{
|
||||
$realCount = Str::length($value) - Str::substrCount($value, "\r\n");
|
||||
|
||||
if($realCount > $this->maxCharacters)
|
||||
{
|
||||
$fail('validation.max.string')->translate(['max' => $this->maxCharacters]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
@csrf
|
||||
<div class="form-group">
|
||||
<label for="input1" class="font-weight-bold">Message</label>
|
||||
<textarea class="form-control" id="input1" name="message" rows="6" placeholder=""></textarea>
|
||||
<textarea class="form-control" id="input1" name="message" rows="6" placeholder="" maxlength="500" required>{{old('message')}}</textarea>
|
||||
<span class="form-text text-muted text-right msg-counter">0/500</span>
|
||||
</div>
|
||||
<div class="form-group form-check">
|
||||
|
|
Loading…
Reference in a new issue