Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么“如果”;所有参与者==0“;还有一些自定义问题显示的消息不正确?_Php_Laravel - Fatal编程技术网

Php 为什么“如果”;所有参与者==0“;还有一些自定义问题显示的消息不正确?

Php 为什么“如果”;所有参与者==0“;还有一些自定义问题显示的消息不正确?,php,laravel,Php,Laravel,我想要下面的登记表: 如果“allParticipants==1”,则应显示以下消息:“请填写所有表单字段。您的票证将发送到{{(\Auth::check())?Auth::user()->email:old('email')}。”(正在运行) 否则,如果“allParticipants==0”并且没有自定义问题,即“$selectedRtype['questions']”为空,则应显示消息“不是必需的附加信息。您的票证将发送到“{(\Auth::check())?Auth::user()->

我想要下面的登记表:

  • 如果“
    allParticipants==1
    ”,则应显示以下消息:“
    请填写所有表单字段。您的票证将发送到{{(\Auth::check())?Auth::user()->email:old('email')}。

    ”(正在运行)
  • 否则,如果“
    allParticipants==0
    ”并且没有自定义问题,即“
    $selectedRtype['questions']
    ”为
    空,则应显示消息“
    不是必需的附加信息。您的票证将发送到“{(\Auth::check())?Auth::user()->email:old('email')}
    ”(此操作正常)
  • 如果“
    allParticipants==0
    ”并且存在自定义问题,即“
    $selectedRtype['questions']
    ”不是
    空的
    ,则应显示消息“
    您的票证将发送到{(\Auth::check())?Auth::user()->email:old('email')}。您只需回答以下自定义问题。

    ”(这不起作用)
但它不适用于第三种情况,因为当“
如果”allParticipants==0
”并且存在自定义问题时,出现的消息是“
不需要其他信息。您的票证将发送到“{(\Auth::check())?Auth::user()->email:old('email')}

”,但在本例中应显示的消息是“
您的票证将发送到{{(\Auth::check())?Auth::user()->email:old('email')}。您只需回答以下自定义问题。

你知道问题在哪里吗

//构成条件的一部分:

<form method="post" id="step1formfree" action="">
    {{csrf_field()}}
    @if (!is_null($allParticipants) && is_int($allParticipants))
        @if($allParticipants == 1)
            <p>Please fill all form fields. Your tickets will be send to <b>{{ (\Auth::check()) ? Auth::user()->email : old('email')}}</b>.</p>
        @else
            // if there are no custom questions the message should be only "Is not necessary additional info. Your tickets will be sent to"
            @if(is_null($selectedRtype['questions']))
                <p>Is not necessary additional info. Your tickets will be sent to
                    <b>{{ (\Auth::check()) ? Auth::user()->email : old('email')}}</b></p>
            // if the user selected in the previous page tickets that have associated custom questions the message should be "Your tickets will be send to....You only need to answer to the custom questions below."
            @else
                <p>Your tickets will be send to <b>{{ (\Auth::check()) ? Auth::user()->email : old('email')}}</b>.
                    You only need to answer the custom questions below.
                </p>
            @endif
        @endif
    @endif
//完整形式

<form method="post" id="step1formfree" action="">
    {{csrf_field()}}
    @if (!is_null($allParticipants) && is_int($allParticipants))
        @if($allParticipants == 1)
            <p>Please fill all fields. Your tickets will be send to <b>{{ (\Auth::check()) ? Auth::user()->email : old('email')}}</b>.</p>
        @elseif(!is_null($selectedRtype['questions']))
           <p>Your tickets will be send to <b>{{ (\Auth::check()) ? Auth::user()->email : old('email')}}</b>.You only need to answer to the custom questions below.</p>
        @else
           <p>Is not necessary additional info. Your tickets will be send to "<b>{{ (\Auth::check()) ? Auth::user()->email : old('email')}}</b></p>
        @endif

        <span id="userData" data-name="{{ auth()->user()->name }}" data-surname="{{ auth()->user()->surname }}"></span>

        @foreach($selectedRtypes as $k => $selectedRtype)
            //{{dd($selectedRtype)}}
            @foreach(range(1,$selectedRtype['quantity']) as $val)
                @if($allParticipants == 1)
                    <h6>Participant - {{$val}} - {{$k}}</h6>
                    <div class="form-check">
                        <input class="form-check-input" type="checkbox" id="fill_auth_info{{ $val }}" data-id="{{ $k }}_{{ $val }}"name="fill_with_auth_info">
                        <label class="form-check-label d-flex align-items-center" for="fill_auth_info{{ $val }}">
                            <span class="mr-auto">Fill with auth user info.</span>
                        </label>
                    </div>
                    <div class="form-group font-size-sm">
                        <label for="name{{ $k }}_{{ $val }}" class="text-gray">Name</label>
                        <input type="text"  id="name{{ $k }}_{{ $val }}" name="participant_name[]" required class="form-control" value="">
                    </div>
                    <div class="form-group font-size-sm">
                        <label for="surname{{ $k }}_{{ $val }}" class="text-gray">Surname</label>
                        <input type="text" id="surname{{ $k }}_{{ $val }}" required class="form-control" name="participant_surname[]" value="">
                    </div>
                    @foreach($selectedRtype['questions'] as $customQuestion)
                        <div class="form-group">
                            <label for="participant_question">{{$customQuestion->question}}</label>
                            <input type="text"
                                   @if($customQuestion->pivot->required == "1") required @endif
                                   class="form-control" name="participant_question[]">
                            <input type="hidden" name="participant_question_required[]"
                                   value="{{ $customQuestion->pivot->required }}">
                            <input type="hidden" value="{{ $customQuestion->id }}" name="participant_question_id[]"/>
                        </div>
                    @endforeach
                @else
                    <input type="hidden" value="foo" name="participant_name[]"/>
                    <input type="hidden" value="bar" name="participant_surname[]"/>
                @endif
                <input type="hidden" name="rtypes[]" value="{{ $selectedRtype['id'] }}"/>
            @endforeach
                    <div class="form-group">
            @if ($allParticipants == 0)
                @foreach($selectedRtype['questions'] as $customQuestion)
                        <label for="participant_question">{{$customQuestion->question}}</label>
                        <input type="text"
                               @if($customQuestion->pivot->required == "1") required @endif
                               class="form-control" name="participant_question[]">
                        <input type="hidden" name="participant_question_required[]"
                               value="{{ $customQuestion->pivot->required }}">
                        <input type="hidden" value="{{ $customQuestion->id }}" name="participant_question_id[]"/>
                    </div>
                @endforeach
            @endif
        @endforeach
    @endif
    <input type="submit" href="#step2"
           id="goToStep2Free" class="btn btn-primary btn float-right next-step" value="Go to step 2"/>
</form>

{{csrf_field()}}
@如果(!is_null($allParticipants)&&is_int($allParticipants))
@如果($allParticipants==1)
请填写所有字段。您的票证将发送到{{(\Auth::check())?Auth::user()->email:old('email')}

@elseif(!is_null($selectedType['questions'])) 您的票证将发送到{(\Auth::check())?Auth::user()->email:old('email')}。您只需回答以下自定义问题

@否则 不需要其他信息。您的票证将发送到“{(\Auth::check())?Auth::user()->email:old('email')}”

@恩迪夫 @foreach($SelectedType为$k=>$SelectedType) //{{dd($selectedRtype)} @foreach(范围(1,$SelectedType['quantity'])为$val) @如果($allParticipants==1) 参与者-{{$val}}-{{$k} 填写身份验证用户信息。 名称 姓 @foreach($SelectedType['questions']作为$customQuestion) {{$customQuestion->question} pivot->required==“1”)required@endif class=“form control”name=“参与者\问题[]”> @endforeach @否则 @恩迪夫 @endforeach @如果($allParticipants==0) @foreach($SelectedType['questions']作为$customQuestion) {{$customQuestion->question} pivot->required==“1”)required@endif class=“form control”name=“参与者\问题[]”> @endforeach @恩迪夫 @endforeach @恩迪夫
很好地显示了问题转储:
{{dd($selectedRtype['questions'])}

如何将if检查(和
dd
)简化为:
@if($selectedType->questions->count())
?这可能会使您的调试/阅读变得更容易,也更接近您试图用人类语言表达的内容。请看:

请记住,在上面的
dd
中,您已经看到,即使没有结果,也会始终返回illumb\Support\Collection的实例。您基本上是在检查$x=new stdClass;if($x){…},它将始终返回true(对于is_null检查,则始终返回false)

根据返回的集合,if检查的值可能与dd时的值不同——理论上您是100%正确的——在is_null检查中应该为false,但事实并非如此。我认为如果您检查计数或
!$selectedType->questions->isEmpty()
…甚至是
$selectedType->questions->first()
,它可能会让问题暴露出来


**注意-完整表单和部分是不同的。部分的代码有if检查问题。似乎“完整表单”只检查所有参与者。是否可能您没有将代码包括在最终表单中?

谢谢,但使用“$SelectedType->questions…”始终显示正在尝试获取非对象的属性“@joW-查看我的编辑和注释-可能您没有将完整的代码复制到最终表单中?谢谢,我用完整的表单更新了问题。请您尝试使用部分中的确切代码。否则将导致问题(不允许第三个检查为真,因为$allParticipants==1已通过该检查)即它可能永远不会显示“不需要其他信息”。使用该代码,它会显示错误消息
<form method="post" id="step1formfree" action="">
    {{csrf_field()}}
    @if (!is_null($allParticipants) && is_int($allParticipants))
        @if($allParticipants == 1)
            <p>Please fill all fields. Your tickets will be send to <b>{{ (\Auth::check()) ? Auth::user()->email : old('email')}}</b>.</p>
        @elseif(!is_null($selectedRtype['questions']))
           <p>Your tickets will be send to <b>{{ (\Auth::check()) ? Auth::user()->email : old('email')}}</b>.You only need to answer to the custom questions below.</p>
        @else
           <p>Is not necessary additional info. Your tickets will be send to "<b>{{ (\Auth::check()) ? Auth::user()->email : old('email')}}</b></p>
        @endif

        <span id="userData" data-name="{{ auth()->user()->name }}" data-surname="{{ auth()->user()->surname }}"></span>

        @foreach($selectedRtypes as $k => $selectedRtype)
            //{{dd($selectedRtype)}}
            @foreach(range(1,$selectedRtype['quantity']) as $val)
                @if($allParticipants == 1)
                    <h6>Participant - {{$val}} - {{$k}}</h6>
                    <div class="form-check">
                        <input class="form-check-input" type="checkbox" id="fill_auth_info{{ $val }}" data-id="{{ $k }}_{{ $val }}"name="fill_with_auth_info">
                        <label class="form-check-label d-flex align-items-center" for="fill_auth_info{{ $val }}">
                            <span class="mr-auto">Fill with auth user info.</span>
                        </label>
                    </div>
                    <div class="form-group font-size-sm">
                        <label for="name{{ $k }}_{{ $val }}" class="text-gray">Name</label>
                        <input type="text"  id="name{{ $k }}_{{ $val }}" name="participant_name[]" required class="form-control" value="">
                    </div>
                    <div class="form-group font-size-sm">
                        <label for="surname{{ $k }}_{{ $val }}" class="text-gray">Surname</label>
                        <input type="text" id="surname{{ $k }}_{{ $val }}" required class="form-control" name="participant_surname[]" value="">
                    </div>
                    @foreach($selectedRtype['questions'] as $customQuestion)
                        <div class="form-group">
                            <label for="participant_question">{{$customQuestion->question}}</label>
                            <input type="text"
                                   @if($customQuestion->pivot->required == "1") required @endif
                                   class="form-control" name="participant_question[]">
                            <input type="hidden" name="participant_question_required[]"
                                   value="{{ $customQuestion->pivot->required }}">
                            <input type="hidden" value="{{ $customQuestion->id }}" name="participant_question_id[]"/>
                        </div>
                    @endforeach
                @else
                    <input type="hidden" value="foo" name="participant_name[]"/>
                    <input type="hidden" value="bar" name="participant_surname[]"/>
                @endif
                <input type="hidden" name="rtypes[]" value="{{ $selectedRtype['id'] }}"/>
            @endforeach
                    <div class="form-group">
            @if ($allParticipants == 0)
                @foreach($selectedRtype['questions'] as $customQuestion)
                        <label for="participant_question">{{$customQuestion->question}}</label>
                        <input type="text"
                               @if($customQuestion->pivot->required == "1") required @endif
                               class="form-control" name="participant_question[]">
                        <input type="hidden" name="participant_question_required[]"
                               value="{{ $customQuestion->pivot->required }}">
                        <input type="hidden" value="{{ $customQuestion->id }}" name="participant_question_id[]"/>
                    </div>
                @endforeach
            @endif
        @endforeach
    @endif
    <input type="submit" href="#step2"
           id="goToStep2Free" class="btn btn-primary btn float-right next-step" value="Go to step 2"/>
</form>