I'm trying to send emails with form details in. I succeed to send one with email information but when I'm trying to add more data, i get errors such as undefined var etc.
After sending the mail, I'd like to redirect to a new view saying ' Thx for contacting us" before getting back to index. Any help ? :(
Controller
namespace App\Http\Controllers;
use App\Http\Requests\ContactFormRequest;
class AboutController extends Controller {
public function create()
{
return view('contact');
}
public function store(ContactFormRequest $request)
{
\Mail::send('emails.hello',
array(
'event_type' => $request-> get('event_type'),
'date' => $request->get('date'),
'personnes' => $request->get('personnes'),
'lieu' =>'lieu',
'rayon_km' => $request->get('rayon_km'),
'accessoires' => $request->get('accessoires'),
'civilite' => $request->get('civilite'),
'nom' => $request->get('nom'),
'prenom' => $request->get('prenom'),
'email' => $request->get('email'),
'telephone' => $request->get('telephone'),
'telephone2' => $request->get('telephone2'),
'horaires' => $request->get('horaires'),
),
function($message)
{
$message->from('wj@wjgilmore.com');
$message->to('x@gmail.com', 'Admin')->subject('Form');
});
return \Redirect::route('contact')->with('message', 'Thanks for contacting us!');
}}
Form
{!! Form::open(array('route' => 'contact', 'class' => 'form')) !!}
<h3>Prestation</h3>
<label class="grid_16">
<span class="label grid_5">x</span>
{!! Form::select('event_types', $event_types) !!}
</label>
<label class="grid_16">
<span class="label grid_5">x</span>
<input type="date" name="date"/>
</label>
<label class="grid_16">
<span class="label grid_5">x</span>
{!! Form::select('personnes', $personnes) !!}
</label>
<label class"grid_16">
<span class="label grid_5">x</span>
{!! Form::text('lieu') !!}
</label>
<label class="grid_16">
<span class="label grid_5">x</span>
{!! Form::select('rayon_km', $rayon_km) !!}
</label>
<label class="grid_16">
<span class="label grid_5">Tx</span>
<ul class="grid_8">
@foreach($accessoires as $value => $front)
<li>
<label>
{!! Form::checkbox('accessoires[]', $value) !!}
{{ $front }}
</label>
</li>
@endforeach
</ul>
</label>
<label class="grid_16">
<span class="label grid_5">x</span>
<textarea name="informations" rows="5" cols="70"></textarea>
</label>
<h3>Coordonnées</h3>
<label class="grid_16">
<span class="label grid_5"> x</span>
{!! Form::select('civilite', $civilite) !!}
</label>
<label class="grid_24">
<span class="label grid_5"> x</span>
{!! Form::text('prenom') !!}
</label>
<label class="grid_24">
<span class="label grid_5"> x</span>
{!! Form::text('nom') !!}
</label>
<label class="grid_24">
<span class="label grid_5"> x</span>
{!! Form::text('telephone') !!}
</label>
<label class="grid_24">
<span class="label grid_5"> x</span>
{!! Form::email('email') !!}
</label>
<label class="grid_24">
<span class="label grid_5"> x</span>
{!! Form::text('telephone2') !!}
</label>
<label class="grid_24">
<span class="label grid_5"> x</span>
{!! Form::text('horaires') !!}
</label>
<div class="grid_24">
{!! Form::submit('Envoyer', '', array('class'=>'btn btn-primary')) !!}
</div>
{!! Form::close() !!}
ContactFormRequest
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class ContactFormRequest extends Request { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; }
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'prenom' => 'required',
'nom' => 'required',
'email' => 'required|email',
//
];
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire