Support the ongoing development of Laravel.io →
posted 10 years ago
Validation
Last updated 2 years ago.
0

Can you please show us your form?

Last updated 2 years ago.
0
	Add User


{{ Form::open(array('action' => 'AdmincpController@adduser')) }}

{{ Form::hidden('do', 'users') }}


<div class="form-group {{set_error('first_name', $errors)}}">

		{{ Form::label('first_name', 'First Name', ['class' => 'control-label col-sm-3']) }}

	<div class="col-sm-7">

		{{ Form::text('first_name', Input::old('first_name'), ['class' => 'form-control']) }}

	
		{{ get_error('first_name', $errors) }}
	</div>
</div>


<div class="form-group {{set_error('last_name', $errors)}}">

		{{ Form::label('last_name', 'Last Name', ['class' => 'control-label col-sm-3']) }}

	<div class="col-sm-7">

		{{ Form::text('last_name', Input::old('last_name'), ['class' => 'form-control']) }}

	
		{{ get_error('last_name', $errors) }}
	</div>
</div>

<div class="form-group {{set_error('password', $errors)}}">

		{{ Form::label('password', 'Password', ['class' => 'control-label col-sm-3']) }}

	<div class="col-sm-7">

		{{ Form::password('password', Input::old('password'), ['class' => 'form-control']) }}

	
		{{ get_error('password', $errors) }}
	</div>
</div>


<div class="form-group {{set_error('email', $errors)}}">

		{{ Form::label('email', 'Email', ['class' => 'control-label col-sm-3']) }}

	<div class="col-sm-7">

		{{ Form::text('email', Input::old('email'), ['class' => 'form-control']) }}

	
		{{ get_error('email', $errors) }}
	</div>
</div>


<div class="form-group {{set_error('usergroup', $errors)}}">

		{{ Form::label('usergroup', 'User Group', ['class' => 'control-label col-sm-3']) }}

	<div class="col-sm-7">

		{{ Form::select('usergroup', $data['grouplist'], Input::old('usergroup'), ['class' => 'form-control']) }}
	
		{{ get_error('usergroup', $errors) }}
	</div>
</div>


<div class="form-group ">

	
	<div class="col-sm-10">

		{{ Form::submit('Save User') }}
	</div>
</div>

{{ Form::close() }}
Last updated 2 years ago.
0

Probably not the issue, but is this a type? Admincpcontroller ?

Have you tried writing your validation rules as follows?

$validator = Validator::make(
array(
    'name' => 'Dayle',
    'password' => 'lamepassword',
    'email' => '[email protected]'
),
array(
    'name' => 'required',
    'password' => 'required|min:8',
    'email' => 'required|email|unique:users'
)

);

Last updated 2 years ago.
0

The controller type is valid. I have tried making the validation rules as you described, no success.

Last updated 2 years ago.
0

Hi jafo232,

Try running each validation rule separately to isolate the error.

In your models did you change the table name or in the migration did you change the columns name?

Last updated 2 years ago.
0

I have not changed the table or column names. The error does not happen until I include the unique validation rule. (Edit: I did try one at a time) The laravel log says:

"Next exception 'ErrorException' with message 'Illegal string offset 'name' (View: /home/mysite/source/app/views/admincp/users.blade.php)' in /home/mysite/source/vendor/laravel/framework/src/Illuminate/Html/FormBuilder.php:226"

That code is:

	public function input($type, $name, $value = null, $options = array())
	{
	if ( ! isset($options['name'])) $options['name'] = $name;
Last updated 2 years ago.
0

try this

'email' => 'required|email|unique:users,email'
Last updated 2 years ago.
0

If I modify the input function in FormBuilder.php by adding this line, it fixes it:

if (!is_array($options)) $options = json_decode($options);

I am assuming that sending a json_encoded array in the view is problematic then?

Example:

		{{ Form::email('email', Input::old('email'), ['class' => 'form-control']) }}
Last updated 2 years ago.
0

nadimtuhin said:

try this ...'email' => 'required|email|unique:users,email'

I did try that already with no luck

Jafo232 said:

I am assuming that sending a json_encoded array in the view is problematic then?

Actually I tried changing those to arrays and still had the issue.

Last updated 2 years ago.
0

Found it. The issue was this:

{{ Form::password('password', Input::old('password'), ['class' => 'form-control']) }}

Password doesn't take a display value. Once I changed it to this:

{{ Form::password('password', ['class' => 'form-control']) }}

Problem solved.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Jafo232 jafo232 Joined 6 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.