Motomichi Works Blog

モトミチワークスブログです。その日学習したことについて書いている日記みたいなものです。

vagrantその19-19 cakephp入門をやってみる(Formその10) FormHelper まとめ

参考にさせて頂いたページ

フォーム送信とForm Helper(5/5):初心者のためのCakePHP2.0 プログラミング入門

SampleController.phpの記述内容

参考ページにならって以下の通り。

<?php
App::uses('AppController', 'Controller');
App::uses('Sanitize', 'Utility');

class SampleController extends AppController {

  public function index() {
    $this->modelClass = null;
    if ($this->request->data){
      $result = "[result]";
      $result .= "<br>text1: " . Sanitize::
          stripAll($this->request->data['text1']);
      $result .= "<br>check1: " . 
          $this->request->data['check1'];
      $result .= "<br>radio1: " . 
          $this->request->data['radio1'];
      $result .= "<br>select1: " . 
          $this->request->data['select1'];
    } else {
      $result = "no data.";
    }
    $this->set("result", $result);
  }

}

index.ctpの記述内容

参考サイトをもとに少し書き換えてみた結果として、以下の通り。

<h1>Index Page</h1>
<p>this is test View.</p>
<p><?php echo $result; ?></p>
<p>
  <?php
    echo $this->Form->create(false,
        array('type'=>'post','action'=>'.'));
    echo $this->Form->label('text1',"message");

    //$this->Form->text(名前,連想配列);
    echo $this->Form->text(
      "text1",
      array(
        "class" => "example_class",
        "placeholder" => "example_placeholder"
      )
    );

    //$this->Form->checkbox(名前,連想配列);
    echo $this->Form->checkbox(
      "check1",
      array(
        "id" => "example_id",
        "class" => "example_class"
      )
    );
    echo $this->Form->label('check1',"checkbox1");

    //$this->Form->radio(名前,連想配列,連想配列);
    echo $this->Form->radio(
      "radio1",
      array(
        "value1" => "label1",
        "value2" => "label2",
        "value3" => "label3",
      ),
      array(
        "class" => "example_class"
      )
    );

    //$this->Form->select(名前,配列,連想配列);
    echo $this->Form->select(
      "select1",
      array(
        "value1" => "label1",
        "value2" => "label2",
        "value3" => "label3",
      ),
      array(
        "class" => "example_class"
      )
    );

    //
    echo $this->Form->end("送信");
  ?>
</p>
</div>

スルーしてたけど

label要素は以下のに出力してる。

echo $this->Form->label('check1',"checkbox1");