samedi 29 octobre 2016

Laravel form validation doesn't seem to work

I'm making my first form in Laravel and the generation of the form is all working. It's just that the store function seems to blindly return the user to my contact page irrelevant of the result of the form validation.

My controller looks like this:

namespace App\Http\Controllers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\DB;

use App\Http\Requests\ContactFormRequest;

class ContactController extends Controller {

  public function create(){
      return view('contact');
  }

  public function store(ContactFormRequest  $request) {

      return \Redirect::route('contact')
        ->with('message', 'Thanks for contacting us!');

  }
}

And the form handler like this:

namespace App\Http\Requests;
use Illuminate\Http\Request;

class ContactFormRequest extends Request {
  public function authorize() {
    return true;    // don't need to be registered to run form so true
  }
  public function rules() {
    return [
        'email' => 'required|email',
    ];
  }
}

And the form like this:

  <ul>
    @foreach($errors->all() as $error)
      <li></li>
    @endforeach
   </ul>
   @if(Session::has('message'))
      <div class="alert alert-info">
        
      </div>
   @endif


 {!! Form::open(array('route' => 'contact_store', 'id' => 'contactCallMeForm')) !!}         
 {!! Form::label('Your E-mail Address') !!}
 {!! Form::text('email', null,  array('required',  'class'=>'form-control',  'placeholder'=>'Your e-mail address')) !!}
 {!! Form::submit('Contact Us!',  array('class'=>'btn btn-primary')) !!} 
 {!! Form::close() !!}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2fhF4pd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire