Table des matières

Formulaire de contact

Controller

<?php
 
 
class ContactController extends \BaseController {
 
	public function __construct(){
		$this->beforeFilter('csrf', array('on' => 'post'));
	}
 
 
	public function getIndex(){
		return View::make('contact');
	}
 
	public function postIndex(){
		$rules = array(
				'nom'      => 'required',
				'email'    => 'required|email',
				'objet'    => 'required|min:3',
				'Message'  => 'required|min:5'
		);
		$messages = array(
		  'email.required'    => 'L\'adresse e-mail est obligatoire'
		);
		$v = Validator::make(Input::all(), $rules, $messages);
		if($v->passes()){
			Mail::send('emails.contact', Input::all(), function($m){
				$m->to('info@gmail.com')->subject('[Mon site] Contact via le site web');
			});	 			
			return Redirect::to('contact')->with('flash_success','Le message a bien été envoyé.');
		}else{
			return Redirect::to('contact')->withErrors($v)->withInput(Input::all());
		}
 
	}
 
}

Vue

@extends('layouts.master')
 
@section('contenu')
<div class="row-fluid">
    <div class="span3"></div>
    <div class="span6">
 
{{Form::open(array('url'=>'contact','method'=>'post','id'=>'formSB'))}}
<fieldset>
	<legend>Formulaire de contact</legend>
	<div class="control-group{{ $errors->has('nom') ? ' error' : '' }}">
		{{Form::label('nom','Nom', array('class'=>'control-label'))}}
		{{Form::text('nom','',array('maxlength'=>40, 'size'=>20 ))}}
		<span class="help-inline">{{ $errors->has('nom') ? $errors->first('nom') : '' }}</span>
	</div>
	<div class="control-group{{ $errors->has('email') ? ' error' : '' }}">
		{{Form::label('email','E-mail', array('class'=>'control-label'))}}
		{{Form::text('email','',array('maxlength'=>100, 'size'=>20))}}
		<span class="help-inline">{{ $errors->has('email') ? $errors->first('email') : '' }}</span>
	</div>
	<div class="control-group{{ $errors->has('objet') ? ' error' : '' }}">
		{{Form::label('objet','Objet', array('class'=>'control-label'))}}
		{{Form::text('objet','',array('maxlength'=>150, 'size'=>20))}}
		<span class="help-inline">{{ $errors->has('objet') ? $errors->first('objet') : '' }}</span>
	</div>
	<div class="control-group{{ $errors->has('Message') ? ' error' : '' }}">
		{{Form::label('Message','Message', array('class'=>'control-label'))}}
		{{Form::textarea('Message','',array('cols'=>20, 'rows'=>4))}}<br>
		<span class="help-inline">{{ $errors->has('Message') ? $errors->first('Message') : '' }}</span>
	</div>
	{{Form::submit('Envoyer',array('class'=>'btn'))}}
</fieldset>
	<div class="msgerreur" style="display:none">Merci de compléter les champs marqués d\'une flèche.</div>				
	{{Form::token()}}		
{{Form::close()}}
 
 
    </div>
    <div class="span3"></div>
</div>
 
@stop