Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adamjhn's avatar

Phone field is appearing twice but it should appear only once

I have a registration form below for a user register in a congress.

But the form is not appearing correctly in this scenario:

  • "all_participants" is 0 in the conferences table, which means that is not necessary to collect info (name and surname) of each participant, is only necessary to collect info of the user that is doing the registration (the authenticated user)
  • And the user selected at least 1 registration type (in this case "general") that have custom questions associated.

In this scenario, because "all_particpants" is "0" the form should only show 1 field for the user to answer. Because the name and surname are got directly from the authenticated user, that is the user that is doing the registration. And because all_partiicipants is "0" is only necessary to collect the answers to custom questions for the user that is doing the registration, so the "Phone" field should appear only once. So the form in this scenario should be like:

The issue is that in this scenario the Phone field is appearing twice and not only once. Do you know where is the issue?

Code in the view to show the form:


    <?php $counter = 1; ?>
    @foreach($selectedRtypes as $k => $selectedRtype)
        @foreach(range(1,$selectedRtype['quantity']) as $val)
    
            @if($allParticipants == 1)
                <h6> Participant - {{$counter}} - {{$k}}</h6>
              
                <div class="form-group font-size-sm">
                    <label for="name{{ $k }}_{{ $counter }}" class="text-gray">Name</label>
                    <input type="text" id="name{{ $k }}_{{ $counter }}"
                           name="participant[{{$counter}}][name]" required
                           class="form-control" value="">
                </div>
                <div class="form-group font-size-sm">
                    <label for="surname{{ $k }}_{{ $counter }}" class="text-gray">Surname</label>
                    <input type="text" id="surname{{ $k }}_{{ $counter }}"
                           required class="form-control"
                           name="participant[{{$counter}}][surname]" value="">
                </div>
                @foreach($selectedRtype['questions'] as $customQuestion)
                    <div class="form-group">
                        <label for="participant_question">{{$customQuestion->question}}</label>
                        @if($customQuestion->hasOptions() && in_array($customQuestion->type, ['checkbox', 'radio_btn', 'select_menu']))
                            {!! $customQuestion->getHtmlInput(
                                $customQuestion->name,
                                $customQuestion->options,
                                ($customQuestion->pivot->required == '1'),
                                $customQuestion->type,
                                $counter
                                )
                            !!}
    
                        @else
                            {!! $customQuestion->getHtmlInput(
                                $customQuestion->name,
                                [],
                                ($customQuestion->pivot->required == '1'),
                                $customQuestion->type,
                                $counter)
    
                            !!}
                        @endif
                        <input type="hidden"
                               name="participant_question_required[]"
                               value="{{ $customQuestion->pivot->required }}">
                        <input type="hidden"
                               value="{{ $customQuestion->id }}"
                               name="participant[{{$counter}}][question_id]"/>
                    </div>
                @endforeach
                <input type="hidden" name="participant[{{$counter}}][rtypes]"
                       value="{{ $selectedRtype['id'] }}"/>
            @endif
    
    
            @if ($allParticipants == 0)
                @foreach($selectedRtype['questions'] as $customQuestion)
                    <div class="form-group">
                        <label for="participant_question">{{$customQuestion->question}}</label>
                        @if($customQuestion->hasOptions() && in_array($customQuestion->type, ['checkbox', 'radio_btn', 'select_menu']))
                            {!! $customQuestion->getHtmlInput(
                                $customQuestion->name,
                                $customQuestion->options,
                                ($customQuestion->pivot->required == '1'),
                                $customQuestion->type,
                                $counter
                                )
                            !!}
    
                        @else
                            {!! $customQuestion->getHtmlInput(
                                $customQuestion->name,
                                [],
                                ($customQuestion->pivot->required == '1'),
                                $customQuestion->type,
                                $counter)
    
                            !!}
                        @endif
                        <input type="hidden"
                               name="participant_question_required[]"
                               value="{{ $customQuestion->pivot->required }}">
                        <input type="hidden"
                               value="{{ $customQuestion->id }}"
                               name="participant[{{$counter}}][question_id]"/>
                    </div>
                @endforeach
    
                <input type="hidden" name="participant[{{$counter}}][rtypes]"
                       value="{{ $selectedRtype['id'] }}"/>
                <input type="hidden" value=""
                       name="participant[{{$counter}}][name]"/>
                <input type="hidden" value=""
                       name="participant[{{$counter}}][surname]"/>
            @endif
        <?php $counter++; ?>
        @endforeach
    @endforeach

The " {{dd($selectedRtypes)}}" shows:

    array:2 [▼
      "general" => array:6 [▼
        "quantity" => "2"
        "price" => 5
        "subtotal" => 10
        "total" => 10
        "questions" => Collection {#243 ▼
          #items: array:1 [▶]
        }
        "id" => 1
      ]
      "plus" => array:6 [▼
        "quantity" => "1"
        "price" => 10
        "subtotal" => 10
        "total" => 20
        "questions" => Collection {#247 ▼
          #items: []
        }
        "id" => 2
      ]
    ]
0 likes
1 reply
adamjhn's avatar

It is appearing twice because the registration type "general" has the custom question "Phone" associated so it shows the custom question "Phone" twice because were selected two registration types of type "general". But it should only appear once because "all_participants" is 0 so is only necessary to collect the answer of the user that is doing the registration.

Please or to participate in this conversation.