Answer the question
In order to leave comments, you need to log in
How to apply different validation rules depending on the value of the form select?
Hello.
How can I apply different validation rules to a form field depending on the value of another form field?
<form method = "post">
<!--В зависимости от значения этого селекта применяем нужные правила валидации-->
<select name = "validate">
<option value = "email">E-mail</option>
<option value = "numeric">Numeric</option>
<option value = "url">URL</option>
</select>
<!--К этому полю-->
<input name = "content">
<input type = "submit">
</form>
Answer the question
In order to leave comments, you need to log in
Something like this
public function rules()
{
switch (\Request::get('validate')) {
case 'email':
return [
'content' => 'email|required'
];
break;
case 'url':
return [
'content'=>'url|required'
];
break;
case 'numeric':
return [
'content'=>'numeric|required'
];
break;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question