Sending and leaving the session form

0

I created a form with laravel. My site and onepage however when I submit my form the page back to home session I would like it to stay in contact session is this possible?

Follow my code:

The html:

 @if (count($errors) > 0)
                    <div class="alert alert-danger">
                        <ul>
                            @foreach ($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>
                    </div>
                @endif

                @if (session('message'))
                    <div class="alert alert-success">
                        {!! session('message')  !!}
                    </div>
                @endif
                {!! Form::open(array('action' => 'FormController@postContato', 'role' => 'form', 'class'=>'form-block contact')) !!}
                {!! Form::text('nome', null, array('placeholder'=>'Digite nome', 'class'=>'form-control')) !!}
                {!! Form::text('email', null, array('placeholder'=>'Digite e-mail', 'class'=>'form-control')) !!}
                {!! Form::text('telefone', null, array('placeholder'=>'Digite seu Telefone', 'class'=>'form-control')) !!}
                {!! Form::textarea('mensagem', null, array('placeholder'=>'Mensagem', 'class'=>'form-control', 'rows'=>'5')) !!}
                {!! Form::submit('Enviar Mensagem', array('class' => 'btn-black btn-blue bounce-green send'), array('id' => 'btn_submit')) !!}
                {!! Form::close() !!}

Route:

Route::post('/', 'FormController@postContato');

Controller:

<?php

namespace App\Http\Controllers;

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

class FormController extends Controller
{
    public function index() {
        return view('/');
    }

    public function postContato(Request $request) {
        $rules = array( 'nome' => 'required', 'email' => 'required|email', 'telefone' => 'required', 'mensagem' => 'required' );
        $errors = [
            'required'    => 'O campo :attribute é obrigatório.',
            'email'    => 'Digite um email válido.',
        ];
        $validation = Validator::make($request->all(), $rules, $errors);
        $data = array();
        $data['nome'] = $request->input("nome");
        $data['email'] = $request->input("email");
        $data['telefone'] = $request->input("telefone");
        $data['mensagem'] = $request->input("mensagem");


        if($validation->passes()) {
            /*Mail::send('emails.contato', $data, function($message) {
                $message->from($request->input("email"), $request->input("nome"));
                $message->to('[email protected]') ->subject('TorreForte');
            });*/
            return redirect('/')->with('message', 'Mensagem enviada com sucesso!');
        }
        return redirect('/')->withErrors($validation);
    }
}
    
asked by anonymous 02.09.2016 / 17:06

1 answer

1

Usually when using onepage layout the pages / sections are identified by hashtag #, example, #pagina1 #pagina2 , then in its URL that returns to the form adds the "link" section.

if($validation->passes()) {
    /*Mail::send('emails.contato', $data, function($message) {
        $message->from($request->input("email"), $request->input("nome"));
        $message->to('[email protected]') ->subject('TorreForte');
    });*/
    //note que troquei de / para /#contato
    return redirect('/#contato')->with('message', 'Mensagem enviada com sucesso!');
}
//note que troquei de / para /#contato
return redirect('/#contato')->withErrors($validation);
    
02.09.2016 / 17:23