سؤال

I have this issue with Laravel and building a form based on routed controllers and using x.blade.php files. The page shows fine, I can enter data and test the rules, that is all fine. The issue is with submitting the data, I hit submit and an error comes back with "the Email address is required".

The email address has data in it when I hit submit, Mmind you I have this working when the $rules and the $validation are in the routes file. I just don't understand how its not seeing the data in the email field.
The database has a table named users in it with the appropriate fields.

Routes file:

Route::get('register', 'LoginController@getRegistration');
Route::post('logging', 'LoginController@postCreate');

User.php file:

<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface 
{

public static $rules = array(
'email' => 'required|email|unique:users',
'password' => 'required|alpha_num|between:6,20|same:password_confirm',
'password_confirm' => 'required'
);
//user.php default values
}

LoginController.php file:

<?php
class LoginController extends BaseController
{
   public function __construct()
   {
     $this->beforeFilter('csrf', array('on'=>'post'));
   }
   public $layout = 'layout.registration';
   public function getRegistration()
   {
    //
   }
   public function postCreate()
   {
     $validation = Validator::make(Input::all(), User::$rules);
     if ($validation->fails())
   {
      return Redirect::to('register')->withErrors($validation)->withInput();
   }
      $users = new User;
      $users->email = Input::get('email');
      $users-password = Hash::make(Input::get('password'));
      if ($users->save())
   {
      Auth::loginUsingId($users->id);
      return Redirect::to('profile');
   }
      return Redirect::to('register')-withInput();
   }
}

registration.blade.php file:

<h2>New Registeration</h2>
    <?php $messages = $errors-all('<p style="color:red">:message</p> ?>
    <?php foreach ($messages as $msg): ?>
       </= $msg ?>
    <?php endforeach; ?>
<?= Form::open(array('action'=>'LoginController@postCreate')) ?>
<?= Form::label('email', 'Email Address: ') ?>
<?= Form::text('text', Input::old('email')) ?>
<br />
<?= Form::label('password', 'Password: ') ?>
<?= Form::password('password') ?>
<br />
<?= Form::label('password_confirm', 'Password Confirm: ') ?>
<?= Form::password('password_confirm') ?>
<br />
<?= Form::submit('Submit') ?>
<?= Form::close() ?>
هل كانت مفيدة؟

المحلول

You don't have an email field. You have a label for an email field, but when you actually output the field itself, you are setting it's name as text.

Try <?= Form::text('email', Input::old('email')) ?> instead.

And also to save you some headache later, as was commented, you've spelled your constructor function wrong. As it is now, it will never hit the csrf validation.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top