我有以下表格供用户在国会注册。
此部分中的用户可以使用每个参与者的姓名和姓氏。
我有一个复选框“使用经过身份验证的用户信息填写以下字段”。如果用户选中此复选框,我想使用经过身份验证的用户的name
和surname
填充输入字段名称和姓氏。你知道如何实现这个目标吗?
该复选框仅允许用户,如果他也是参与者,而不是在复选框中输入他的姓名和姓氏,他不需要输入他的姓名,它是自动的。
@foreach(range(1,$selectedRtype['quantity']) as $test)
<h6>Participant - 1 - {{$test}}</h6>
<div class="form-check">
<input class="form-check-input" type="radio" name="" value="">
<label class="form-check-label d-flex align-items-center" for="exampleRadios1">
<span class="mr-auto">Fill the following fields with the authenticated user information.</span>
</label>
</div>
<div class="form-group font-size-sm">
<label for="participant_name" class="text-gray">Name</label>
<input type="text" name="participant_name[]" required class="form-control" value="">
</div>
<div class="form-group font-size-sm">
<label for="participant_surname" class="text-gray">Surname</label>
<input type="text" required class="form-control" name="participant_surname[]" value="">
</div>
@endforeach
完整格式:
<form method="post" id="step1" action="">
{{csrf_field()}}
@if (!empty($allParticipants))
@if($allParticipants == 1)
<p>Please enter the following information:.</p>
@foreach($selectedRtypes as $selectedRtype)
@foreach(range(1,$selectedRtype['quantity']) as $test)
<h6>Participant - 1 - {{$test}}</h6>
<div class="form-check">
<input class="form-check-input" type="radio" name="" value="referencias">
<label class="form-check-label d-flex align-items-center" for="exampleRadios1">
<span class="mr-auto">Fill the following fields with the authenticated user information.</span>
</label>
</div>
<div class="form-group font-size-sm">
<label for="participant_name" class="text-gray">Name</label>
<input type="text" name="participant_name[]" required class="form-control" value="">
</div>
<div class="form-group font-size-sm">
<label for="participant_surname" class="text-gray">Surname</label>
<input type="text" required class="form-control" name="participant_surname[]" value="">
</div>
@endforeach
@endforeach
@endif
@else
<p>Is not necessary additional info the tickets will be send to Auth::user()->email.</p>
@endif
<input type="submit" href="#step2free"
id="goToStep2Free" class="btn btn-primary btn float-right next-step" value="Go to step 2"/>
</form>
答案 0 :(得分:0)
您可以使用jQuery来执行此操作。
只需使用您想要的字段初始化变量:
<script>
var name = {{ $name }}
var surname = {{ $surname }}
</script>
并将一个监听器放在复选框onchange事件:
$(document).ready(function() {
$('#checkboxId').click(function() {
if ($(this).is(':checked')) {
$('#inputNameId').val(name);
$('#inputSurnameId').val(surname);
} else {
$('#inputNameId').val('');
$('#inputSurnameId').val('');
}
});
});