Question

I am developing a registration form. Everything is working fine but I am having problem with alpha and alpha_num validation.

Here is my Model(employee.php)

   <?php

     class Employee extends Eloquent
     {
          protected $table='employee';

          public static $rules = array(
            'first_name' => 'required|min:2',
            'last_name' => 'required|min:2',
            'username' => 'required|min:3|unique:employee',
            'password' => 'required|alpha_num|between:6,12|confirmed',
            'confirm_password' => 'required|aplha_num|between:6,12',
            'department' => 'required',
            'post' => 'required'
    );
     }
   ?>

Here is my controller (EmployeeController.php)

    public function store()
{        
     //validate the user input
     $validator = Validator::make(Input::all(),Employee::$rules);

     //process the login
     if ($validator->fails()) 
     {
         return Redirect::to('employee/create')
            ->withErrors($validator)
            ->withInput(Input::except('password'));
     }
     else
     {
         //store
         $employee = new Employee;
     $employee->first_name = Input::get('first_name');
     $employee->last_name = Input::get('last_name');
     $employee->username = Input::get('username');
     $employee->password = Hash::make(Input::get('password'));
     $employee->department = Input::get('department');
     $employee->post = Input::get('post');
     $employee->save();

    //redirect to the main page
    Session::flash('message','Successfully added employee');
        return Redirect::to('employee');
    }
  }

My create.blade.php file

   @extends('layouts.master')

   @section('navigation')
   @parent
   @stop

   @section('content')
<h1>Add New Employee</h1>
<!--if there are any errors,display here-->
{{ HTML::ul($errors->all()) }}

{{ Form::open(array('url'=>'employee','class'=>'form-horizontal')) }}
    <div class="control-group">
        {{ Form::label('first_name','Enter First Name',array('class'=>'control-label')) }}
        <div class="controls">
            {{ Form::text('first_name',Input::old('first_name'),array('placeholder'=>'First Name')) }}
        </div>
    </div>

    <div class="control-group">
        {{ Form::label('last_name','Enter Last Name',array('class'=>'control-label')) }}
        <div class="controls">
            {{ Form::text('last_name',Input::old('last_name'),array('placeholder'=>'Last Name')) }}
        </div>
    </div>

    <div class="control-group">
        {{ Form::label('username','Enter Username',array('class'=>'control-label')) }}
        <div class="controls">
            {{ Form::text('username',Input::old('username'),array('placeholder'=>'Username')) }}
        </div>
    </div>

    <div class="control-group">
        {{ Form::label('password','Enter Password',array('class'=>'control-label')) }}
        <div class="controls">
            {{ Form::password('password',array('placeholder'=>'Password')) }}
        </div>
    </div>

    <div class="control-group">
        {{ Form::label('confirm_password','Confirm Password',array('class'=>'control-label')) }}
        <div class="controls">
            {{ Form::password('confirm_password',array('placeholder'=>'Password')) }}
        </div>
    </div>


    <div class="control-group">
        {{ Form::label('department','Select Department',array('class'=>'control-label')) }}
        <div class="controls">
            {{ Form::select('department',array('it'=>'IT','finance'=>'finance','management'=>'Management','marketing'=>'Marketing')) }}
        </div>
    </div>

    <div class="control-group">
        {{ Form::label('post','Enter Post',array('class'=>'control-label')) }}
        <div class="controls">
            {{ Form::select('post',array('E'=>'Employee','PM'=>'Project Manager','CEO'=>'Executive CEO','MD'=>'Managing Director')) }}
        </div>
    </div>

    <div class="control-group">
        <div class="controls">
            {{ Form::submit('Register',array('class'=>'btn btn-success')) }}
        </div>
    </div>
{{ Form::close() }}

@stop

I am getting BadMethodCallException

Method [validateAplhaNum] does not exist.

Method [validateAplha] does not exist.

Was it helpful?

Solution

It's because you've spelt alpha_num wrong in your confirm_password validation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top