我想从 href 存储当前用户 $emp->id ,并在输入值中使用,就像在下面编写的代码中一样。有可能吗?或者如果可能的话请帮助我?如果这个问题不是一个大问题,那么我很抱歉。
<a href="{{'/employee'}}?id={{$emp->id}}" type="button" name="user_id" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Apply Attribute
</a>
<form action="{{'/rating'}}" method="post">
{{csrf_field()}}
<input type="hidden" name="user_id" value="{{store here current user}}">
</form>
像这样的Href:
<a href="{{$emp->id}}" type="button" id="uu_id" class="btn btn-primary uu"
data-toggle="modal" data-target="#myModal"> Apply Attribute </a>
使用此脚本从 Href 获取值:
<script type="text/javascript">
$(document).ready(function() {
$(".uu").click(function(event) {
var u_id = $(this).attr('href');
event.preventDefault();
document.getElementById("hiddenVal").value = u_id;
});
});
</script>
在你的表单中是这样的:
<form action="{{'/rating'}}" method="post">
{{csrf_field()}}
<input type="submit" style="margin-bottom: 10px;" class="btn btn-success
pull-right" name="apply" value="Apply"/>
<input type="hidden" name="hiddenVal" id="hiddenVal" />
</form>
最后如何在控制器中获取此值并保存到数据库:
public function store(Request $request)
{
$rates = new Rating;
$user_id = $_POST['hiddenVal'];
$rates->user_id = $user_id;
$rates->save();
return redirect('/employee');
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句