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('');
            }  
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀