Contact form error View [contact.contact] not found

Published 1 week ago by Mikejs

Hi I have followed this guide http://www.easylaravelbook.com/blog/2015/02/09/creating-a-contact-form-in-laravel-5-using-the-form-request-feature/ to create a simple contact form for my website the form worked for sending but then got stuck with error View [contact.contact] not found.

The form loaded I filled out the info and sent a test message which arrived in my mailbox but instead of a message it got stuck on the error above?

My routes

Route::get('contact', ['as' => 'contact', 'uses' => [email protected]']); Route::post('contact', ['as' => 'contact_store', 'uses' => [email protected]']);

My contact.blade.php [code] @foreach($errors->all() as $error) {{ $error }} @endforeach

{!! Form::open(array('route' => 'contact_store', 'class' => 'form')) !!} {!! Form::label('Your Name') !!} {!! Form::text('name', null, array('required', 'class'=>'form-control', 'placeholder'=>'Your name')) !!} {!! Form::label('Your E-mail Address') !!} {!! Form::text('email', null, array('required', 'class'=>'form-control', 'placeholder'=>'Your e-mail address')) !!} {!! Form::label('Your Message') !!} {!! Form::textarea('message', null, array('required', 'class'=>'form-control', 'placeholder'=>'Your message')) !!} {!! Form::submit('Contact Us!', array('class'=>'btn btn-primary')) !!} {!! Form::close() !!}[/code]

My AboutController [code] namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests; use App\Http\Controllers\Controller;

class AboutController extends Controller { public function create() { return view('contact.contact'); }

public function store(ContactFormRequest $request) { \Mail::send('emails.contact', array( 'name' => $request->get('name'), 'email' => $request->get('email'), 'user_message' => $request->get('message') ), function($message) { $message->from('email'); $message->to([email protected]', 'Admin')->subject('Contact'); }); return \Redirect::route('contact')->with('message', 'Thanks for contacting us!'); }

}[/code]

and my contact.blade.php [code] You received a message from TODOParrot.com:

Name: {{ $name }}

{{ $email }}

{{ $user_message }} [/code] I already had "laravelcollective/html": "5.1.*", in my composer.json and I added the following to app.php

Providers [code] Illuminate\View\ViewServiceProvider::class, Illuminate\Html\HtmlServiceProvider::class, [/code] Aliases [code] 'Form'=> Illuminate\Html\FormFacade::class, 'Html'=> Illuminate\Html\HtmlFacade::class, [/code] If I create a folder called contact and add my contact.blade.php I get this error

Undefined variable: name (View:

Not sure what's wrong in the guide it uses \Mail::send('contact.contact', but the contact.blade.php is created under the emails folder?ed I filled out the info and sent a test message which arrived in my mailbox but instead of a message it got stuck on the error above?

My routes [code] Route::get('contact', ['as' => 'contact', 'uses' => [email protected]']); Route::post('contact', ['as' => 'contact_store', 'uses' => [email protected]']);

My contact.blade.php

{!! Form::open(array('route' => 'contact_store', 'class' => 'form')) !!}

{!! Form::label('Your Name') !!} {!! Form::text('name', null, array('required', 'class'=>'form-control', 'placeholder'=>'Your name')) !!} {!! Form::label('Your E-mail Address') !!} {!! Form::text('email', null, array('required', 'class'=>'form-control', 'placeholder'=>'Your e-mail address')) !!} {!! Form::label('Your Message') !!} {!! Form::textarea('message', null, array('required', 'class'=>'form-control', 'placeholder'=>'Your message')) !!} {!! Form::submit('Contact Us!', array('class'=>'btn btn-primary')) !!} {!! Form::close() !!} [/code] My AboutController [code] namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests; use App\Http\Controllers\Controller;

class AboutController extends Controller { public function create() { return view('contact.contact'); }

public function store(ContactFormRequest $request)
{
    \Mail::send('emails.contact',
    array(
        'name' => $request->get('name'),
        'email' => $request->get('email'),
        'user_message' => $request->get('message')
    ), function($message)
{
    $message->from('email');
    $message->to([email protected]', 'Admin')->subject('Contact');
});
     return \Redirect::route('contact')->with('message', 'Thanks for contacting us!');
}

} [/code] and my contact.blade.php [code] You received a message from TODOParrot.com:

Name: {{ $name }}

{{ $email }}

{{ $user_message }}

[/code]

If I create a folder called contact and add my contact.blade.php I get this error

Undefined variable: name (View:

Not sure what's wrong in the guide it uses \Mail::send('contact.contact', but the contact.blade.php is created under the emails folder?

luis02lopez

Hi friend, the "." dot is meaning of the folder like: arriving/welcome.blade.php you use: arriving.welcome

So, if your contact.blade.php is in emails/contact.blade.php you should use emails.contact you should change this part of the tutotial.

PS: Are you facing problems with a undefined variables?

Mikejs

Hi thanks for the reply its not my guide :-) I just want to add a contact form to my app

the guide states you can use /contact to load the form which it does - the problem is after the form is submitted I get a debug error

the message is received - any step by step guides that work with Laravel 5.1 to add a contact form to an existing project?

thanks

Mikejs

Why is this so difficult I thought the point of a framework was to make life simple

I have redone the steps in the guide and now I get

Class 'Illuminate\Html\FormFacade\Form' not found

in my form I am using

{!! Form::open(array('route' => 'contact_store', 'class' => 'form')) !!}

I have installed "illuminate/html":"5.0.*",

and added

    Illuminate\Html\HtmlServiceProvider::class,

and

    'Form'=> Illuminate\Html\FormFacade\Form::class,
    'Html'=> Illuminate\Html\HtmlFacade\Html::class, 

to my app.php

At the moment Laravel = WTF why is everything so difficult

nanpaul68

Why not use [laravelcollective] (https://laravelcollective.com/docs/5.1/html).

or better still you can just add it to the require section of your composer.json file e.g

"require": {
    "laravelcollective/html": "5.1.*"
}

Next, update Composer from the Terminal:

composer update

Next, add your new provider to the providers array of config/app.php:

'providers' => [
    // ...
    Collective\Html\HtmlServiceProvider::class,
    // ...
  ],

Finally, add two class aliases to the aliases array of config/app.php:

'aliases' => [
    // ...
      'Form' => Collective\Html\FormFacade::class,
      'Html' => Collective\Html\HtmlFacade::class,
    // ...
  ],

on your view file:

{{ Form::open(['url' => 'foo/bar']) }}
Mikejs

Thanks for the info I already have

"illuminate/html":"5.0.*",

and added

Illuminate\Html\HtmlServiceProvider::class,

'Form'=> Illuminate\Html\FormFacade\Form::class, 'Html'=> Illuminate\Html\HtmlFacade\Html::class,

I created the form using standard html markup and it works now

Sign In or create a forum account to participate in this discussion.