contact form with Laravel 5.1

2

I need to create a simple contact form with laravel 5.1, however, as I am more of a front-end, I would like some idea of what I can do to create this form, some websites even explain how it is done, but it is not with the current version of laravel, some packagist packages generate a form but also do not explain clearly how to use them.

Can someone give me a light?

    
asked by anonymous 05.07.2015 / 22:57

1 answer

1

To achieve this and very simple

Layout:

{{ Form:: open(array('action' => 'ContactController@getContactUsForm')) }} 

<ul class="errors">
@foreach($errors->all('<li>:message</li>') as $message)

@endforeach
</ul>

<div class="form-group">
{{ Form:: textarea ('message', '', array('placeholder' => 'Message', 'class' => 'form-control', 'id' => 'message', 'rows' => '4' )) }}
</div>



</div>
<div class="modal-footer">
{{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
{{ Form:: close() }}

Add the following route

Route::post('contact_request','ContactController@getContactUsForm

And the following controller

public function getContactUsForm(){

        //Get all the data and store it inside Store Variable
        $data = Input::all();

        //Validation rules
        $rules = array (
            //'first_name' => 'required', uncomment if you want to grab this field
            //'email' => 'required|email',  uncomment if you want to grab this field
            'message' => 'required|min:5'
        );

        //Validate data
        $validator = Validator::make ($data, $rules);

        //If everything is correct than run passes.
        if ($validator -> passes()){

           Mail::send('emails.feedback', $data, function($message) use ($data)
            {
                //$message->from($data['email'] , $data['first_name']); uncomment if using first name and email fields 
                $message->from('[email protected]', 'feedback contact form');
    //email 'To' field: cahnge this to emails that you want to be notified.                    
    $message->to('[email protected]', 'John')->cc('[email protected]')->subject('feedback form submit');

            });
            // Redirect to page
   return Redirect::route('home')
    ->with('message', 'Your message has been sent. Thank You!');


            //return View::make('contact');  
         }else{
   //return contact form with errors
            return Redirect::route('home')
             ->with('error', 'Feedback must contain more than 5 characters. Try Again.');

         }
     }
} 

link

    
06.07.2015 / 12:25