gpt4 book ai didi

php - 下拉列表中的值未传递到 Laravel php 中的 Controller

转载 作者:行者123 更新时间:2023-11-29 13:03:53 25 4
gpt4 key购买 nike

我的 View (“注册”页面)包含一堆输入字段和一个下拉列表。由于某种原因,所有输入字段数据都会顺利传递到 Controller ,但下拉列表中的值不会传递。这使我的代码失败 - 返回以下错误:

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 (myemail@gmail.com, yzmBHUNQTNbE6nGA90Adq1w4BTGXWYyV8mvwNVUoGx4KrMQiAlSSseZ4DkuyitCZNUa5N59nUiOy.iCKie8w3LD0SHs52YCBUp9lt6JbRA0Z6wuqi, 0, ergerg, , 2014-04-10 11:25:42, 2014-04-10 11:25:42, ?))

这是代码:

@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

最佳答案

您的 Carehome 类型选择框没有名称,因此不会传递其数据。它的选项确实有一个名称,但该名称参数不应该存在。

所以代替这个:

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>

使用这个:

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>

关于php - 下拉列表中的值未传递到 Laravel php 中的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22987081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com