Form sending email and exiting session

Asked

Viewed 53 times

0

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

Follows 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);
    }
}

1 answer

1


Usually when using onepage layout the pages/sections are identified by the hashtag #, example, #pagina1 #pagina2, then in your URL that returns to the form adds the "link" of the 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);
  • in this case for example in html is only an id="contact" right

  • I think yes, in the site I’m developing now I do exactly that, in the contact section is like this: <section id="contato" class="">...</div> and the link to it in the menu is #contato

  • worked out dude and nois sauhsuahsua

Browser other questions tagged

You are not signed in. Login or sign up in order to post.