我有这个隐藏的表格
<form method="POST" action="reviews/rate" class="hidden">
{{ csrf_field() }}
<input type="text" name="id" value="{{ $review->id }}">
</form>
单选按钮
<fieldset class="rating" data-rating="{{$review->getAverage()}}" >
<input type="radio" id="star{{$review->id}}_5" class="rate" name="rating{{encrypt($review->id)}}" value="5" /><label class = "star" for="star{{$review->id}}_5" title="Awesome - 5 stars"></label>
<input type="radio" id="star{{$review->id}}_4" class="rate" name="rating{{encrypt($review->id)}}" value="4" /><label class = "star" for="star{{$review->id}}_4" title="Pretty good - 4 stars"></label>
<input type="radio" id="star{{$review->id}}_3" class="rate" name="rating{{encrypt($review->id)}}" value="3" /><label class = "star" for="star{{$review->id}}_3" title="Meh - 3 stars"></label>
<input type="radio" id="star{{$review->id}}_2" class="rate" name="rating{{encrypt($review->id)}}" value="2" /><label class = "star" for="star{{$review->id}}_2" title="Kinda bad - 2 stars"></label>
<input type="radio" id="star{{$review->id}}_1" class="rate" name="rating{{encrypt($review->id)}}" value="1" /><label class = "star" for="star{{$review->id}}_1" title="Sucks big time - 1 star"></label>
</fieldset>
哪种风格
.hidden {Vardas
display: none;
}
和提交表单的jQuery函数
$('.rate').on('click', function(e){
$('.hidden').append(this).submit();
});
.rate是星形单选按钮。使用其事件监听器,我将无线电输入附加到隐藏表单并提交表单。
以下是laravel controller
中请求的输出Request {#42 ▼
#json: null
#convertedFiles: null
#userResolver: Closure {#139 ▶}
#routeResolver: Closure {#141 ▶}
+attributes: ParameterBag {#44 ▼
#parameters: []
}
+request: ParameterBag {#43 ▼
#parameters: array:3 [▼
"_token" => "uVJUAwdUVhukLLFMgy9FIBlGh9LsY836uhjoA0EO"
"id" => "28"
"ratingeyJpdiI6Ijc1R2wyNXYzMVd1QVwvNGZQVERwMXp3PT0iLCJ2YWx1ZSI6IlFRSklDK1NlUlFkcEZMWHVtZWpnNFE9PSIsIm1hYyI6IjhhM2FjODZhZWY0YzNlN2U1ZDYxMTQ0OTljMGViYTg3MmZhMWQ4MGMyOTcxYTgxMzAzMGNiNjgwNzE1YTJmNmQifQ==" => "5"
]
}
+query: ParameterBag {#50 ▶}
+server: ServerBag {#46 ▶}
+files: FileBag {#47 ▶}
+cookies: ParameterBag {#45 ▶}
+headers: HeaderBag {#48 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/reviews/rate"
#requestUri: "/reviews/rate"
#baseUrl: ""
#basePath: null
#method: "POST"
#format: null
#session: Store {#169 ▶}
#locale: null
#defaultLocale: "en"
-isHostValid: true
-isForwardedValid: true
basePath: ""
format: "html"
}
至少id字段值应该随请求一起发布,因为我可以看到它是通过inspect输入的形式,但它始终是“28”,这是错误的。
EDIT。我现在看到费率是正确的,但身份仍然没有。
EDIT。即使每次输入的值都不同,Id总是“28”