cakephp(2.7.8)
PHP 5.6
MySQL 5.6
上記の環境で簡単なクイズアプリを作りました。
以下のように回答を、URLパラメータで渡してます。
http://hogepiyo?aaa?&answer=消費税
この時、以下のようにパラメータに%や数値が含まれていると、不具合がありました。
http://hogepiyo?aaa?&answer=消費税は8%です
Webアプリは初めてでよく分からないのですが、
通常、パラメータは何かメソッド等で変換をかますのでしょうか?
そもそもパラメータには日本語はあまり使わないものでしょうか?
分かる方教えていただけないでしょうか?
宜しくお願い致します。
同日追記
失礼しました。ソースコードをまったく記載してなかったので追記します。
コントローラで受ける際にエンコードすれば解決出来るのかと思います。
ビュー側
ctp
1<?php echo $this->Form->create('Questions', array('controller'=>'Questions', 'url' => '/Questions/', 'type' => 'GET', 'name' => 'frmExam')); ?> 2 3<?php foreach ($choices as $ch): ?> 4 5 <p><button type='submit' name='answer' value='<?= h($ch); ?>' class="btn btn-success btn-lg btn-block"><?= h($ch); ?></button></p> 6 7<?php endforeach; ?> 8 9<?php if ($question_index != 0 && $question_index + 1 != $question_count){ ?> 10 <p><button type="submit" name="end" value="true" class="btn btn-primary btn-lg btn-block">ここまでで終了して採点する</button></p> 11<?php } ?>
表示されるhtml
html
1 <form action="/kako/Questions/" controller="Questions" name="frmExam" id="QuestionsIndexForm" method="get" accept-charset="utf-8"> 2 3 <input type="hidden" name="question_index" value="7"> 4 5 <div class="row"> 6 <div class="col col-md-12"> 7 8 9 <p><button type='submit' name='answer' value='1.いっさい認められていない' class="btn btn-success btn-lg btn-block">1.いっさい認められていない</button></p> 10 11 <p><button type='submit' name='answer' value='2.運用資産全体の10%以内に制限されている' class="btn btn-success btn-lg btn-block">2.運用資産全体の10%以内に制限されている</button></p> 12 13 <p><button type='submit' name='answer' value='3.運用資産全体の20%以内に制限されている' class="btn btn-success btn-lg btn-block">3.運用資産全体の20%以内に制限されている</button></p> 14 15 16 17 18 <p><button type="submit" name="end" value="true" class="btn btn-primary btn-lg btn-block">ここまでで終了して採点する</button></p> 19 </div> 20 </div> 21 </form> 22
コントローラ側
不具合=パラメータに%などがあった場合に、戻り値が空になったため。
パラメータが問題と思い、正誤判定メソッドの中身までは追っていません。
php
1 2public function index() { 3 4 $answer = $this->request->query['answer']; 5 6 //一部省略・・・ 7 8 //正誤判定を行うメソッド 9 $seigo = score($question, $answer); 10 11 12}
URLパラメータは、以下のように渡してます
http://localhost/Questions/?question_index=6&answer=消費税は10%になる予定
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/26 08:03
2018/09/26 08:08
2018/09/26 08:21
2018/09/27 00:30
2018/09/27 01:04
2018/09/27 01:06
2018/09/27 07:34