I have created a form in Laravel 5.4 containing checkbox fields. I am validating on the front-end using parsley.js then on the backend. I want to send the checked values from the checkbox to my email but it produces an error
ErrorException htmlspecialchars() expects parameter 1 to be string, array given(View: C:\XAMPP\htdocs\Joswan\resources\views\emails\contact.blade.php)
Please assist ?
contact.blade.php
<div class="col-sm-6">
<input type="checkbox" class="inputC" name="checkbox[]" value="Toshiba" data-parsley-checkmin="1" required> Toshiba <br>
<input type="checkbox" class="inputC" name="checkbox[]" value="HP" data-parsley-checkmin="1" required> HP<br>
<input type="checkbox" class="inputC" name="checkbox[]" value="Acer" data-parsley-checkmin="1" required> Acer
</div>
Controller
//Contact form in contact page
public function postContact(Request $request){
$this->validate($request, [
'checkbox' => 'required']);
$data = array(
'checkbox' => $request ->checkbox
);
Mail::send('emails.contact', $data, function($message) use ($data){
$message->from($data['email']);
$message->to('info@**********');
});
return redirect()->back();
}
emails.contact.blade.php
<h3> Contact Form </h3>
<div>
<b> Type: </b> <br> <br>
</div>
Aucun commentaire:
Enregistrer un commentaire