参考にさせて頂いたページ
フォーム送信とForm Helper(5/5):初心者のためのCakePHP2.0 プログラミング入門
index.ctpの記述内容
参考ページにならって以下の通り。
echo $this->Form->create(null,
のところだけはecho $this->Form->create(false,
と編集している。
<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");
echo $this->Form->text('text1');
echo $this->Form->checkbox('check1');
echo $this->Form->label('check1',"checkbox1");
echo $this->Form->radio('radio1',
array('male' => '男性',
'female' => '女性'));
echo $this->Form->select('select1',
array("Mac" => 'マック',
"Windows" => 'ウインドウズ',
"Linux" => 'リナックス'));
echo $this->Form->end("送信");
?>
</p>
</div>
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);
}
}
生成されたhtmlソース
Firefoxで見てるんだけど、以下の通り。
<form accept-charset="utf-8" method="post" id="Form" action="/cakephp/sample/.">
<div style="display:none;">
<input type="hidden" value="POST" name="_method">
</div>
<label for="text1">message</label>
<input type="text" id="text1" value="" name="data[text1]">
<input type="hidden" value="0" id="check1_" name="data[check1]">
<input type="checkbox" id="check1" value="1" name="data[check1]">
<label for="check1">checkbox1</label>
<fieldset>
<legend>Radio1</legend>
<input type="radio" value="male" id="radio1Male" name="data[radio1]">
<label for="radio1Male">男性</label>
<input type="radio" checked="checked" value="female" id="radio1Female" name="data[radio1]">
<label for="radio1Female">女性</label>
</fieldset>
<select id="select1" name="data[select1]">
<option value=""></option>
<option value="Mac">マック</option>
<option value="Windows">ウインドウズ</option>
<option selected="selected" value="Linux">リナックス</option>
</select>
<div class="submit">
<input type="submit" value="送信">
</div>
</form>
詳細については次回以降でひとつずつ読んでいこうと思う。