我有一个表单的自定义验证器,其中验证规则是从数据库表中提取的。验证器工作正常,直到我在textarea上使用它。规则很简单,需要',但即使有数据发送,验证也总是失败。
$rules = $this->getFormRules($slug);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to($request->uri)
->withErrors($validator);
} else { ... }
private function getFormRules($slug = null) {
$elements = Element::all();
foreach($elements as $element) {
if(isset($element->mandatory) == 1) {
$rules_array[$element->field_name] = 'required';
}
}
return $rules_array;
}
rules数组如下:
Array (
[Name] => required
[E-mail] => required
[Company] => required
[Phone] => required
[Message] => required
)
Message
是textarea并且在那里继续失败
<form method="POST" action="/form-send" enctype="multipart/form-data">
<input type="hidden"name="_token"value="8ZtkSm7QkloWxAH5x3KkAzW2BS1UEpLv4SkuJ1Nu">
<input type="hidden" name="uri" value="/contact">
<div>
<label>Name<span>*</span></label>
<input type="text" name="Name" value="">
</div>
<div>
<label>E-mail<span>*</span></label>
<input type="text" name="E-mail" value="">
</div>
<div>
<label>Company</label>
<input type="text" name="Company" value="">
</div>
<div>
<label>Phone</label>
<input type="text" name="Phone" value="">
</div>
<div>
<label>Message<span>*</span></label>
<textarea name="Message"></textarea>
</div>
<div>
<button type="submit" name="Send">Send</button>
</div>
</form>