LoginSignup
2
0

More than 3 years have passed since last update.

hiddenの使い方

Last updated at Posted at 2020-10-12

hiddenの使い方

hiddennは疑似要素として扱うことができる。

ctpファイル
echo $this->Form->hidden('isSelectArea',["id" => "isSelectArea"]);

jQueryで疑似要素にval()で値を与える。

js
$(function () {
    $(document).on("change", "#area", function () {
        $("#isSelectArea").val(true); //地域を選択したときにコントローラーで条件分岐をしてaddアクションにリダイレクトさせるためのhidden
        $("#UserConfirmForm").submit(); //一旦confirmアクションに飛ばす
    });
});


最後にコントローラで疑似要素を元にif文などで条件分岐できる

controller
if ($this->request->data["User"]["isSelectArea"]){ 
    //もしisSelectAreaというキーを持っていればここで処理
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0