当前位置: 动力学知识库 > 问答 > 编程问答 >

validation - Laravel validating an input array

问题描述:

I'm new to this laravel. I have this codes from another developer. Now the client want to update the order form products to put in into checkbox the list of products.

Here how product blade looks like:

<input type="checkbox" name="product[]" value="{{ $pp->name }}"> {{ $pp->name }}<br />

and below is the controller: I get "ARRAY" printed as result. Can anyone help me how to get the product array values from checkbox.

function post_sendorder(){

$rules = array(

'name' => 'required|min:2',

'email' => 'required|email',

'phone' => 'required|alpha_dash',

'message' => 'required|min:5',

'product' => 'required'

);

$v = Validator::make(Input::all(), $rules);

$v = $v->fails() ? $v : true;

if($v !== true) return Redirect::to_route('prods')->with_errors($v->errors)->with_input()->with('show_order',true);

Message::send(function($message){

$message->to('[email protected]');

$message->from(Input::get('email'), Input::get('name'));

$message->subject('Keratin Product Order Form');

$message->body(

'<!doctype html>

<html>

<body>'.

'Name: '.Input::get('name').'<br />'.

'Email: '.Input::get('email').'<br />'.

'Phone: '.Input::get('phone').'<br />'.

'Product Ordered:' .Input::get('product'). '<br />'.

'Message: '.Input::get('message').'<br />'.

'</body>

</html>'

);

$message->html(true);

});

if(Message::was_sent()){

return Redirect::to_route('prods')->with('s-message','Your Order Form has been successfully sent!')->with('show_order',true);

}else{

return Redirect::to_route('prods')->with('e-message','Sending Failed!')->with('show_order',true);

}

}

网友答案:

Input::get('product') is the array of product names (name="product[]" value="{{ $pp->name }}").

Instead of 'Product Ordered:' .Input::get('product') you need

'Products Ordered:' . implode(', ', Input::get('product'))

分享给朋友:
您可能感兴趣的文章:
随机阅读: