Reputation: 81
My view (a 'register' page) contains a bunch of input fields and a single dropdown list. For some reason all the input field data is passed to the controller without trouble, but the values from the dropdown list are not passed. This makes my code fail - returning the following error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'carehome_type' cannot be null (SQL: insert into `users` (`email`, `password`, `code`, `active`, `carehome_name`, `carehome_type`, `updated_at`, `created_at`) values ([email protected], yzmBHUNQTNbE6nGA90Adq1w4BTGXWYyV8mvwNVUoGx4KrMQiAlSSseZ4DkuyitCZNUa5N59nUiOy.iCKie8w3LD0SHs52YCBUp9lt6JbRA0Z6wuqi, 0, ergerg, , 2014-04-10 11:25:42, 2014-04-10 11:25:42, ?))
And here is the code:
@extends('layout.main')
@section('content')
<form action="{{URL::route('account-create-post')}}" method="post">
<div class='field'>
Email: <input type='text' name='email'{{ (Input::old('email')) ? 'value="' . e(Input::old('email')) . '"' : ''}}>
@if($errors->has('email'))
{{$errors->first('email') }}
@endif
</div>
<div class='field'>
Username: <input type='text' name='username'{{ (Input::old('username')) ? 'value="' . e(Input::old('username')) . '"' : ''}}>
@if($errors->has('username'))
{{$errors->first('username') }}
@endif
</div>
<div class='field'>
Password: <input type='password' name='password'>
@if($errors->has('password'))
{{ $errors->first('password') }}
@endif
</div>
<div class='field'>
Password (again): <input type='password' name='password_again'>
@if($errors->has('password_again'))
{{ $errors->first('password_again') }}
@endif
</div>
<div>
Carehome type:
<select >
<option value="Independent" name='carehome_type'>Independent</option>
<option value="">-------------</option>
<option value="Chain#_1" name='carehome_type'>Chain#_1</option>
<option value="Chain#_2" name='carehome_type'>Chain#_2</option>
<option value="Chain#_3" name='carehome_type'>Chain#_3</option>
<option value="Chain#_4" name='carehome_type'>Chain#_4</option>
<option value="Chain#_5" name='carehome_type'>Chain#_5</option>
</select>
</div>
<div class='field'>
Carehome name: <input type='text' name='carehome_name'>
@if($errors->has('carehome_name'))
{{ $errors->first('carehome_name') }}
@endif
</div>
<br>
<input type='submit' value='Create account'>
{{ Form::token() }}
</form>
@stop
Upvotes: 0
Views: 331
Reputation: 1620
Your Carehome type selectbox has no name so it's data is not passed. It's options do have a name but that name parameter is not intended to be there.
So instead of this:
Carehome type:
<select >
<option value="Independent" name='carehome_type'>Independent</option>
<option value="">-------------</option>
<option value="Chain#_1" name='carehome_type'>Chain#_1</option>
<option value="Chain#_2" name='carehome_type'>Chain#_2</option>
<option value="Chain#_3" name='carehome_type'>Chain#_3</option>
<option value="Chain#_4" name='carehome_type'>Chain#_4</option>
<option value="Chain#_5" name='carehome_type'>Chain#_5</option>
</select>
Use this:
Carehome type:
<select name="carehome_type">
<option value="Independent">Independent</option>
<option value="">-------------</option>
<option value="Chain#_1">Chain#_1</option>
<option value="Chain#_2">Chain#_2</option>
<option value="Chain#_3">Chain#_3</option>
<option value="Chain#_4">Chain#_4</option>
<option value="Chain#_5">Chain#_5</option>
</select>
Upvotes: 1