简体   繁体   中英

Registration Form using Laravel

Im trying to create a basic registration form on Laravel, following Dayle Rees' tutorial, specifically -> This one

When I load my registration form, everything is fine. But when I submit, it says

The requested URL /testserver/registration was not found on this server.

I am a beginner wishing to learn Laravel better, so any help is appreciated!

This is my register.blade.php

<!doctype html>
<html lang="en">

<head>
</head>

<body>
<h1>Registration Form</h1>

{{ Form::open(array('url' => '/registration')) }}

    <ul class="errors">
    @foreach($errors->all() as $message)
        <li>{{ $message }}</li>
    @endforeach
    </ul>


    {{-- Username field. ------------------------}}
    {{ Form::label('username', 'Username') }}
    {{ Form::text('username') }}

    {{-- Email address field. -------------------}}
    {{ Form::label('email', 'Email address') }}
    {{ Form::email('email') }}

    {{-- Password field. ------------------------}}
    {{ Form::label('password', 'Password') }}
    {{ Form::password('password') }}

    {{-- Password confirmation field. -----------}}
    {{ Form::label('password_confirmation', 'Password confirmation') }}
    {{ Form::password('password_confirmation') }}

    {{-- Form submit button. --------------------}}
    {{ Form::submit('Register') }}

{{ Form::close() }}
</body>

</html>

And this is my routes.php

Route::get('/', function()
{
    return View::make('register');
});

Route::post('/registration', function()
{
    $data=Input::all();

    // Build the validation constraint set.
    $rules = array(
        'username'   => 'required|min:5|max:15',
        'email'      => 'required|email',
        'password'   => 'required|alpha_num|confirm|min:8'
    );

    // Create a new validator instance.
    $validator = Validator::make($data, $rules);

    if ($validator->passes()) {
        // Normally we would do something with the data.
        return 'Data was saved.';
    }

    return Redirect::to('/')->withErrors($validator);

});

Route::filter('csrf', function()
{
    if (Request::forged()) return Response::error('500');
});

Form Action from page source - http://localhost/testserver is my root folder

<form method="POST" action="http://localhost/testserver/registration" accept-charset="UTF-8"><input name="_token" type="hidden" value="LUE1UWguOcyKSbgRyGchfKppRHab504v9p8uEZhQ">

You need to use the method POST in your Route:

Route::post('/registration', function() ...

Otherwise Laravel will not find that route when you POST your form.

If your route is still not being found, it's possible that your .htaccess is not rewriting correctly your urls, to test you can change your form open to:

{{ Form::open(array('url' => '/index.php/registration')) }}

If it works, you'll have to fix your VirtualHost or .htaccess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM