###前提・実現したいこと
Atomを用いてPHPとHTMLを使ったアンケートフォームを作っており、
「アンケートと同じページでエラーチェックを行い、
エラーはその場に表示する」
というシステムを作っているところですが、
エラーチェックをする以前の問題で
PHPのソースコードの一部が
ページ中に出てきてしまいました。
###発生している問題・エラーメッセージ
PHPのみのソース中にある、
/**/でコメントアウトした部分が
全てHTML中に出てきました。
###該当のソースコード
PHP
1 2<?php 3$errors = array(); 4session_start(); 5$gender = ['gender']; 6$attribute = ['attribute']; 7$attribute_custom = ['attribute_custom']; 8$age10 = ['age10']; 9$age1 = ['age1']; 10$like = ['like']; 11if(isset($_POST['submit']) && $_POST['submit'] ==="確認する"){ 12 13if($gender === ""){ 14 $errors['gender'] = "性別が入力されていません。"; 15} elseif (($gender !=="m")&&($gender !=="f")&&($gender !=="X")) { 16$errors['gender'] = "不正なPOSTです。"; 17} 18 19if($attribute === ""){ 20 $errors['attribute'] = "属性が入力されていません。"; 21} 22elseif (htmlspecialchars(ctype_digit(strval($attribute)),ENT_QUOTES) == false) { 23 $errors['attribute'] = "不正なPOSTです。"; 24} 25 26elseif (intval($attribute) > /*21){ 27$errors['attribute'] = "不正なPOSTです。"; 28} 29 30if(($attribute_custom == "") && (intval($attribute) == 21)){ 31 $errors['attribute_custom'] = "属性が入力されていません。"; 32} 33 if (preg_replace( "/^( \n)|( \n)$/", "", $attribute_custom) == false) { 34$errors['attribute_custom'] = "属性が入力されていません。"; 35} 36else 37 { 38$attribute_custom = htmlspecialchars(($attribute_custom),ENT_QUOTES); 39} 40 41 42 43if($age10 === ""){ 44 $errors['age10'] = "年齢(10の位)が入力されていません。"; 45} 46 elseif (htmlspecialchars(ctype_digit(strval($age10)),ENT_QUOTES) == false) { 47 $errors['age10'] = "不正なPOSTです。"; 48} 49 50 elseif (intval($age10) > 10) { 51 $errors['age10'] = "不正なPOSTです。"; 52} 53 54if($age1 === ""){ 55 $errors['age1'] = "年齢(1の位)が入力されていません。"; 56} 57else if (htmlspecialchars(ctype_digit(strval($age1)),ENT_QUOTES) == false) { 58 $errors['age1'] = "不正なPOSTです。"; 59} 60 61else if (intval($age1) > 9) { 62 $errors['age1'] = "不正なPOSTです。"; 63} 64 65if($like === ""){ 66 $errors['like'] = "○○が入力されていません。"; 67} 68 elseif (htmlspecialchars(ctype_digit(strval($like)),ENT_QUOTES) == false) { 69 $errors['like'] = "不正なPOSTです。"; 70} 71 72 elseif (intval($like) > 5) { 73 $errors['like'] = "不正なPOSTです。"; 74} 75} 76 77 $_SESSION = $_POST; 78 header('Location: ./check-att.php'); 79 exit; 80} 81 82?>*/
↓HTML+PHP
性別 <input type="radio" name="gender" value="m" id="m"><label for="m">男性</label> <input type="radio" name="gender" value="f" id="f"><label for="f">女性</label> <input type="radio" name="gender" value="X" id="X"><label for="X">その他</label> <?php echo $errors['gender']; ?> 属性 <input type="checkbox" name="attribute" value="1" id="1"><label for="1">1</label><br><br> <input type="checkbox" name="attribute" value="2" id="2"><label for="2">2</label><br><br> <input type="checkbox" name="attribute" value="3" id="3"><label for="3">3</label><br><br> //同じようなコード <input type="checkbox" name="attribute" value="21" id="21"><label for="21">21</label><br><br> <input type="checkbox" name="attribute" value="22" id="other"><label for="other">その他</label><br><br> <input type="text" name="attribute" placeholder="カスタム" value="" id="attribute-custom"> <?php echo $errors['attribute']; echo $errors['attribute_custom']; ?> 年齢 <select name="age10" required> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> <select name="age1" required> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option></select><br> <?php echo $errors['age10']; echo $errors['age1']; ?> <input type="radio" name="like" value="0"><label>0</label> <input type="radio" name="like" value="1"><label>1</label> <input type="radio" name="like" value="2"><label>2</label><br> <input type="radio" name="like" value="3"><label>3</label> <input type="radio" name="like" value="4"><label>4</label> <input type="radio" name="like" value="5"><label>5</label></p> <?php echo $errors['like']; ?>
###試したこと
Linterで確認したところエラーが見当たらず、
一通りミスを探したものの自分では分かりませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
ツール:Atom 1.18.0
Linter-phpのバージョン:1.3.2
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/12 08:32
退会済みユーザー
2017/08/12 08:46