This is my code, double form so this is the same input name like eg. email. When i send form with empty email field i have an error how can i display one error to one correct form. Now of course i see this error on each form.
<form action="{{ route('signup') }}" method="post" id="webinar-form-{{ $data->id }}">
@csrf
<div >
<input type="text" name="email" value="{{ old('email') }}" placeholder="Adres email">
<button type="submit" >Sign Up</button>
</div>
@error('email')
<div role="alert">
<span >{{ $message }}</span>
</div>
@enderror
</form>
<form action="{{ route('signup') }}" method="post" id="webinar-form-{{ $data->id }}">
@csrf
<div >
<input type="text" name="email" value="{{ old('email') }}" placeholder="Adres email">
<button type="submit" >Sign Up</button>
</div>
@error('email')
<div role="alert">
<span >{{ $message }}</span>
</div>
@enderror
</form>
CodePudding user response:
You need to change the name of your email, probably something like this
<form action="{{ route('signup') }}" method="post" id="webinar-form-{{ $data->id }}">
@csrf
<div >
<input type="text" name="email_1" value="{{ old('email_1') }}" placeholder="Adres email">
<button type="submit" >Sign Up</button>
</div>
@error('email_1')
<div role="alert">
<span >{{ $message }}</span>
</div>
@enderror
</form>
<form action="{{ route('signup') }}" method="post" id="webinar-form-{{ $data->id }}">
@csrf
<div >
<input type="text" name="email" value="{{ old('email_2') }}" placeholder="Adres email">
<button type="submit" >Sign Up</button>
</div>
@error('email_2')
<div role="alert">
<span >{{ $message }}</span>
</div>
@enderror
</form>
Because your input name is same for both form. And you can set the variable in your controller to match the name
CodePudding user response:
You need to use array validation in laravel
$request->validate([
"email" => "required|array",
"email.*" => "required|email|unique:table_name",
]);
Use this code in controller and check it's working or not.