-1

I have use Illuminate\Support\Facades\Input; declared at the beginning of my controller so I'm not sure why it is throwing this error. I can't test this very well because the form only works on the production server and not my development server.

This is the controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Validator;
use Redirect;
use Mail;

use App\Http\Requests;

class contact extends controller
{
    // This function will show the view
    public function showForm()
    {
        return view('pages.contact');
    }

    public function handleFormPost()
    {
        $input = Input::only('name', 'email', 'msg');

        $validator = Validator::make($input,
            array(
                'name' => 'required',
                'email' => 'required|email',
                'msg' => 'required',
            )
        );

        if ($validator->fails())
        {
            return Redirect::to('contact')->with('errors', $validator->messages());
        } else { // the validation has not failed, it has passed


            // Send the email with the contactemail view, the user input
            Mail::send('contactemail', $input, function($message)
            {
                $message->from('idocompscihw@gmail.com', 'Your Name');

                $message->to('idocompscihw@gmail.com');
            });

            // Specify a route to go to after the message is sent to provide the user feedback
            return Redirect::to('thanks');
        }

    }
}

This is the form

<div class="container">
    <h1>A basic contact form</h1>
    <form id="contact" method="post" class="form" role="form">

        @if(Session::has('errors'))
            <div class="alert alert-warning">
                @foreach(Session::get('errors')->all() as $error_message)
                    <p>{{ $error_message }}</p>
                @endforeach
            </div>
        @endif

        <div class="row">
            <div class="col-xs-6 col-md-6 form-group">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                <input class="form-control" id="name" name="name" placeholder="Name" type="text"autofocus="">
            </div>
            <div class="col-xs-6 col-md-6 form-group">
                <input class="form-control" id="email" name="email" placeholder="Email" type="text">
            </div>
        </div>
        <textarea class="form-control" id="message" name="msg" placeholder="Message" rows="5"></textarea>
        <br>
        <div class="row">
            <div class="col-xs-12 col-md-12 form-group">
                <button class="btn btn-primary pull-right" type="submit">Submit</button>
            </div>
        </div>
    </form>
</div>

Any help would be greatly appreciated! Thanks!

user2238780
  • 37
  • 1
  • 7
  • 2
    Almost the same post from another account? You should have edited [this one](http://stackoverflow.com/questions/37202978/fatal-error-class-app-http-controllers-input-not-found-when-sending-a-form) instead of posting a new question from another account. – Ivanka Todorova May 13 '16 at 07:44
  • It's a different problem though. Sorry if I am submitting it poorly. Just want to fix the problem so I can sleep – user2238780 May 13 '16 at 07:46
  • @user2238780 Looks like the same problem, with the same answer. – ceejayoz May 13 '16 at 15:06

2 Answers2

1

Couple of solutions

Try this:

$input = \Input::only('name', 'email', 'msg');

Or try changing this:

use Illuminate\Support\Facades\Input;

to this:

use Input;
haakym
  • 12,050
  • 12
  • 70
  • 98
1

Laravel 5 moved input into the Request.

https://laravel.com/docs/5.2/requests#retrieving-input

Either inject the request into the function:

public function handleFormPost(Request $request) {
    $input = $request->only('whatever');

or use the Request facade (you'll need a use Request; at the top of the file):

public function handleFormPost() {
    $input = Request::only('whatever');
ceejayoz
  • 176,543
  • 40
  • 303
  • 368