duanliao3826 2018-05-01 19:49
浏览 31
已采纳

选中复选框时,使用auth用户信息填充字段

I have the form below for a user to register in a congress.

There is this section where the user inser the name and surname of each participant.

I have a checkbox "Fill the following fields with the authenticated user information." and if the user select this checkbox I want to populate the input fields name and surname with the name and surname of the authenticated user. Do you know how to achieve that?

The checkbox is only to allow the user to, if he is also a participant, instead of enter his name and surname click in the checkbox and he dont need to enter his name and surname, its automatic.

@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

Full form:

 <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>
  • 写回答

1条回答 默认 最新

  • douhuang2673 2018-05-01 22:16
    关注

    You can use jQuery to do this.

    Just initialize the variables with the fields you want:

    <script>
        var name = {{ $name }}
        var surname = {{ $surname }}
    </script>
    

    And put a listener at the checkbox onchange event:

    $(document).ready(function() {
        $('#checkboxId').click(function() {
            if ($(this).is(':checked')) {
                $('#inputNameId').val(name);
                $('#inputSurnameId').val(surname);
            } else {
               $('#inputNameId').val('');
               $('#inputSurnameId').val('');
            }  
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决