1

私はここ数時間、学生向けの入力フォームに取り組んでいます。私はほとんどすべてを0ハイカップで実行しましたが、回避策を考えることができない1つの小さな問題に遭遇しました。ドロップダウンメニューがあり、その検証は次のとおりです。

 }
        if(empty($why) === true) {
            $errors[] = 'Please make sure to select the proper reasoning for your vistit today!';
    }

デフォルトの変数は空または単にvalue=""(空)に設定されています。..

次に検証する必要があるのは、生徒が「その他」オプションを選択した場合、一般的な理由が見つからない生徒のために特別に作成されたコメントボックスに、少なくとも10文字と最大30文字を挿入する必要があるということです。財政援助事務所への彼らの訪問。これは私がこれのために持っているものです(それはところで機能していません):

if(isset($why) === Other) {
        $errors[] = 'Please add a comment explaining why you are visiting the office.';
}

したがって、全体として、学生が他を選択した場合は、「コメントボックス」に、なぜ彼または彼女がオフィスを訪問しているのかについて簡単な要約を書かなければならないという検証を書くのに助けが必要です。

どんな助けでも素敵でしょう。ありがとうございました。

4

2 に答える 2

1

'other'フィールドのtextareaが呼び出されたとしましょう$other

if(empty($why)){
  $errors[] = 'Please select a reason';
}elseif($why == 'Other' && empty($other)){
  $errors[] = 'You selected Other. Please enter a reason why';
}

最小文字数と最大文字数を設定しようとしているので、コードはおそらく上記よりも詳細にする必要がありますが、要点はわかりますか?

===ところで、演算子の代わりに演算子を使用したい理由はわかりません==。彼らはまったく同じことをしますが===、それが同じタイプであるかどうかをチェックします。これがスクリプトにどのように役立つかはわかりません。

于 2012-12-26T00:10:40.290 に答える
0

For if(isset($why) === Other), shouldn't Other be in quotes since $why will return the dropdown menu selection's value as text?

So if(isset($why) === 'Other') should work assuming that "Other" is the name of the dropdown menu's Other selection option.

Edit: Looking at your code again, you are comparing an isset() value to another var (Other). You want to have it as if(isset($why) && $why === 'Other') so this way you check that $why is set and it also equals the text "Other". The === operator is also checking to see if $why and Other are of the same type so you should check the rest of your code to make sure $why and Other are of same type.

于 2012-12-26T00:04:22.107 に答える