I'm new to Laravel and am trying to figure out how to validate user input.
I have a form with several text fields, a textarea and a checkbox:
{{ Form::text('firstname', '', ['placeholder' => 'First Name', 'class' => 'form-control']) }}
{{ Form::text('lastname', '', ['placeholder' => 'Last Name', 'class' => 'form-control']) }}
{{ Form::email('email', '', ['placeholder' => 'Email', 'class' => 'form-control']) }}
{{ Form::textarea('question', '', ['placeholder' => 'Question', 'class' => 'form-control']) }}
{{ Form::checkbox('terms_and_conditions', 'yes') }}
{{ Form::label('terms_and_conditions', 'I agree to terms and conditions') }}
The validation rules are:
public static $rules = array(
'firstname' => 'required|between:2,20',
'lastname' => 'required|between: 2,30',
'email' => 'required|email',
'question' => 'required|max: 5000',
'terms_and_conditions' => 'required|accepted',
);
The text fields are all validating as expected, but I cannot get the checkbox field to validate. I echoed the json of $input to the view and can verify that the model is receiving the terms_and_conditions checkbox value, so I don't understand why it won't validate?
If I add any new fields or change a field's name those fields won't validate as well.
Am I missing something?
{{ Form::checkbox('terms_and_conditions', 1) }}
– Mitch