I made sign up form, but there some are problems with passwords. i enter exactly the same passwords in password field and confirm password field but it fails
The password confirmation confirmation does not match.
my sign up form
<div class="form-group">
{!! Form::password('password', ['class' => 'form-control','placeholder' => '*Password']) !!}
</div>
<div class="form-group">
{!! Form::password('password_confirmation', ['class' => 'form-control', 'placeholder' => '*Password Confirm']) !!}
</div>
my validations
'password' => 'required|between:8,255',
'password_confirmation' => 'confirmed',
i also try this
'password' => 'required|between:8,255',
'password_confirmation' => 'required|between:8,255|confirmed',
and this
'password' => 'required|between:8,255|confirmed',
'password_confirmation' => 'required|between:8,255|confirmed',
but still doesn't work
This is best approach for password confirmation:
'password' => 'required|between:8,255|confirmed'
Explain:
confirmed: The field under validation must have a matching field of foo_confirmation.
For example,
password field named: password
password confirmation field would be: password_confirmation
Then the confirmed property will add default check for password confirmation.
Try
'password' => 'required|between:8,255|confirmed'
Note the confirmed is added to password validation, you dont have to add the rules twice because a confirm field needs to have the same fields.
Your validation should be like :
'password' => 'required | confirmed ',
'password_confirmation' => 'required ',
For more details See Here
I am using Laravel 5.2
and I am able to work this out using
'password' => 'required|min:8|same:confirm_password'
Validator::extend('old_password', function ($attribute, $value, $parameters, $validator) {
return Hash::check($value, current($parameters));
},
'Current password is wrong!'
);
$request->validate([
'old_password' => 'required|old_password:' . $user->password,
'password' => 'required|confirmed|min:6',
'password_confirmation' => 'required|same:password'
]);
confirmed must be passed into password validation rule:
'password' => 'required|between:8,255|confirmed',
'password_confirmation' => 'required',
$validator_password = validator::make($request->all(), [
'old_password' => ['required', 'string', 'min:8', 'old_password:' . $user->password],
'new_password' => 'required|confirmed|min:6',
'password_confirmation' => 'required|same:new_password'
]);
Related
In my project, I got many forms, so I've decided to specify each one with an iscription field, for exemple: Kids' form => <input = 'hidden' name = 'inscripted_in' value = 'kids'>. I want to set each one with a default value, but whenever I sign in, I get this error message:
SQLSTATE[HY000]: General error: 1364 Field 'inscripted_at' doesn't have a default value
Although when I go to Laravel Debug, I still get the inserted constant value, what's the problem?
This is one of my forms
<div class="InputBox">
<input type="hidden" name="inscripted_at" value="Adults">
<input type="hidden" name="status" value="pending">
</div>
my controller:
public function store(Request $req)
{
$this->validate($req,[
'name' => 'required|max:120',
'surname' => 'required|max:120',
'job' => 'required|max:120',
'day' => 'required',
'month' => 'required',
'year' => 'required',
'hobby' => 'required|max:120',
'help' => 'required|max:120',
'place' => 'required|max:120',
'residence' => 'required|max:120',
'email' => 'required|email|unique:users',
'photo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'scholar_year' => 'required|max:120',
'tel' => 'required|regex:/(05)[0-9]{8}/',
]);
Chababounauser::create($req->all());
return redirect()->route('chababounausers.index')
->with('success','chababouna User inserted successfully.');
}
Check the fillable property of the Chababounauser model.
P.S.: Please, don't put spaces in HTML between attribute name and it's value.
Isn't 'inscripted_at' a default column in the database giving the date of inscription ? If so, you can't default a value to that kind of output.
I am using Google reCaptcha v3. I am trying to implement it onto my profile page.It's load and shown in my page ,but when I want to verify it ,it does not work ,I am using this package:https://github.com/RyanDaDeng/laravel-google-recaptcha-v3#settings
in this config :
'secret_key' => env('RECAPTCHA_V3_SECRET_KEY', '6LcqC'),
'site_key' => env('RECAPTCHA_V3_SITE_KEY', '6LcqnrO-K-xb'),
in this blade :
<form>
{!! GoogleReCaptchaV3::renderOne('contact_us_id','contact_us') !!}
</form>
in my controller:
public function get_data_edit(Request $request)
{
$request->validate(
[
'phone' => ['required', 'max:11', new phone],
'year' => 'nullable|numeric',
'month' => 'nullable|numeric|max:12',
'day' => 'nullable|numeric|max:31',
'sex' => 'nullable|boolean',
'marital_status' => 'nullable|boolean',
'f_name' => 'required|max:15',
'l_name' => 'required|max:20',
'job' => 'nullable|string',
'email' => 'nullable|email',
'national_code' => 'nullable|min:10|max:10',
'family_role' => 'nullable|string',
'g-recaptcha-response' => [new GoogleReCaptchaV3ValidationRule('contact_us')]
],
[]
);
where is my problem ?
I want to check if the log in details i.e the email is in the database and echo error like "Email Does Not Exists" in the front-end.
$this->validate($request,[
'email' => 'required',
'password' => 'required',
]);
Above is my current validation.
How do i check if the email exists before logging them in.
$this->validate($request,[
'email' => 'required|unique:users,email', // users is table name,email is column
'password' => 'required',
]);
in blade you can do as follows
#error('email')
<div class="alert alert-danger">{{ $message }}</div>
#enderror
You may use custom validation. Here is an example:
$this->validate($request,[
'email' => ['required', function ($attribute, $value, $fail) {
$email = User::where('email', $value)->first();
if ($email == null) {
$fail($attribute.' does not exist.');
}
},],
'password' => 'required',
]);
How could I validate if the checkbox is ticked?
public $rules = [
'name' => 'required',
'email' => 'required|email',
'phone' => 'required',
'terms' => 'required',
];
'terms' is the name of the checkbox. Now I get the alert about required field even if it is checked.
HTML:
<input type="checkbox" name="terms" value="1" id="terms"/>
Simple HTML5 attribute required is also not working.
Wouter Van Damme has it right. You simply need to use the trait listed in that documentation. like so:
public $rules = [
'name' => 'required',
'email' => 'required|email',
'phone' => 'required',
'terms' => 'required|accepted',
];
here is an october specific link although the answers are the same.http://octobercms.com/docs/services/validation#rule-accepted
I'm building my first app with Laravel 5.2 & Laravel Spark. The front end is built using Vue.js I believe and despite adding the following to register-common-form.blade.php:
<!-- Username -->
<div class="form-group" :class="{'has-error': registerForm.errors.has('username')}">
<label class="col-md-4 control-label">Username</label>
<div class="col-md-6">
<input type="name" class="form-control" name="username" v-model="registerForm.username" autofocus>
<span class="help-block" v-show="registerForm.errors.has('username')">
#{{ registerForm.errors.get('username') }}
</span>
</div>
</div>
I can't actually see a way to fully register that extra field so that it is picked up for error handling. I've got it so that the UserRepository handles the field and inserts it, but just can't get the front end errors to show properly.
Is anyone able to help with this at all?
Okay I finally stumbled across it :D
In Laravel\Spark\Interactions\Auth\CreateUser.php there is a $rules method like so:
public function rules($request)
{
return [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
'vat_id' => 'max:50|vat_id',
'terms' => 'required|accepted',
];
}
All I have done is add my username field, and it works brilliantly!
public function rules($request)
{
return [
'name' => 'required|max:255',
'username' => 'required|unique:users',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
'vat_id' => 'max:50|vat_id',
'terms' => 'required|accepted',
];
}
Above answer is just for validation rules you also need to navigate to spark\src\Repositories\UserRepository.php and add 'username' => $data['username'], to the create() method like this:
public function create(array $data)
{
$user = Spark::user();
$user->forceFill([
'name' => $data['name'],
'username' => $data['username'], // ADDED THIS
'email' => $data['email'],
'password' => bcrypt($data['password']),
'confirmation_code' => str_random(30),
'last_read_announcements_at' => Carbon::now(),
'trial_ends_at' => Carbon::now()->addDays(Spark::trialDays()),
])->save();
return $user;
}