HTML
1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 <meta charset="UTF-8"> 5 <title>narratica</title> 6</head> 7<body> 8 9<div class="form" style="width:600px;"> 10 <form action = "upload.php" method = "POST"> 11 <div class="custom"> 12 <label> 13 <textarea id="comment" name="comment" cols="60" rows="12"></textarea> 14 </label> 15 <table frame="void" style="border:none" id="tbl"> 16 <tr> 17 <th style="text-align: left; font-family: 'Hiragino Maru Gothic ProN',serif;">名前</th> 18 <th style="text-align:left; width:40px; font-family: 'Hiragino Maru Gothic ProN',serif;">好きな食べ物</th> 19 <th style="width:40px;"> </th> 20 <th style="width:40px;"> </th> 21 </tr> 22 <tr> 23 <td style="border:1px #1abc9c solid;"><label for="txt1"></label><input class="inpval" type="text" id="txt1" name="txt1" value="" size="30" style="border: none"></td> 24 <td style="border:1px #1abc9c solid; border-top-style: none; border-left-style: none; border-right-style: none; border-bottom-style: none;"> 25 <label> 26 <select name="select1" class="select_box"> 27 <option>好きな食べ物</option> 28 <option>ぽてと</option> 29 <option>にく</option> 30 <option>ぴーまん</option> 31 <option>たまねぎ</option> 32 <option>にんじん</option> 33 <option>ねぎ</option> 34 <option>ぶたにく</option> 35 <option>ひきにく</option> 36 </select> 37 </label> 38 </td> 39 <td style=" width:40px; font-family: 'Hiragino Maru Gothic ProN',serif;"><input class="edtbtn" type="button" id="edtBtn1" value="確定" onclick="editRow(this)"></td> 40 <td style=" width:40px; font-family: 'Hiragino Maru Gothic ProN',serif;"><input class="delbtn" type="button" id="delBtn1" value="削除" onclick="deleteRow(this)"></td> 41 </tr> 42 </table> 43 <div>新しい行を追加:<input type="button" id="add" name="add" value="追加" class="addbtn" onclick="appendRow()"></div> 44 <input class="square_btn" type = "submit" value ="そうしん"> 45 </div> 46 </form> 47</div> 48</body> 49<script> 50 51 /* 52 * appendRow: テーブルに行を追加 53 */ 54 function appendRow() 55 { 56 let objTBL = document.getElementById("tbl"); 57 if (!objTBL) 58 return; 59 60 const count = objTBL.rows.length; 61 62 // 最終行に新しい行を追加 63 const row = objTBL.insertRow(count); 64 65 // 列の追加 66 const c1 = row.insertCell(0); 67 const c2 = row.insertCell(1); 68 const c3 = row.insertCell(2); 69 const c4 = row.insertCell(3); 70 71 // 各列にスタイルを設定 72 c1.style.cssText = "border:1px #1abc9c solid; text-align:right; width:40px;"; 73 c2.style.cssText = "border:1px #1abc9c solid; border-top-style: none; border-left-style: none; border-right-style: none; border-bottom-style: none;"; 74 c3.style.cssText = "width:40px;"; 75 c4.style.cssText = "width:40px;"; 76 77 // 各列に表示内容を設定 78 c1.innerHTML = '<input class="inpval" type="text" id="txt' + count + '" name="txt' + count + '" value="txt' + count + '" size="30" style="border: none;">'; 79 c2.innerHTML = '<select class="select_box" name="select' + count + '"> <option>役割</option> <option>主人公</option> <option>協力者</option> <option>依頼者</option> <option>犠牲者</option> <option>狂言回し</option> <option>敵</option> <option>ライバル</option> <option>支援者</option> </select>'; 80 c3.innerHTML = '<input class="edtbtn" type="button" id="edtBtn' + count + '" value="確定" onclick="editRow(this)">'; 81 c4.innerHTML = '<input class="delbtn" type="button" id="delBtn' + count + '" value="削除" onclick="deleteRow(this)">'; 82 83 // 追加した行の入力フィールドへフォーカスを設定 84 const objInp = document.getElementById("txt" + count); 85 if (objInp) 86 objInp.focus(); 87 88 } 89 90 /* 91 * deleteRow: 削除ボタン該当行を削除 92 */ 93 function deleteRow(obj) 94 { 95 96 let i; 97 if (!obj) 98 return; 99 100 const objTR = obj.parentNode.parentNode; 101 const objTBL = objTR.parentNode; 102 103 if (objTBL) 104 objTBL.deleteRow(objTR.sectionRowIndex); 105 106 // id/name ふり直し 107 let tagElements = document.getElementsByTagName("input"); 108 if (!tagElements) 109 return false; 110 111 // <input type="text" id="txtN"> 112 let seq = 1; 113 for (i = 0; i < tagElements.length; i++) 114 { 115 if (tagElements[i].className.match("inpval")) 116 { 117 tagElements[i].setAttribute("id", "txt" + seq); 118 tagElements[i].setAttribute("name", "txt" + seq); 119 ++seq; 120 } 121 } 122 123 // <input type="button" id="edtBtnN"> 124 seq = 1; 125 for (i = 0; i < tagElements.length; i++) 126 { 127 if (tagElements[i].className.match("edtbtn")) 128 { 129 tagElements[i].setAttribute("id", "edtBtn" + seq); 130 ++seq; 131 } 132 } 133 134 // <input type="button" id="delBtnN"> 135 seq = 1; 136 for (i = 0; i < tagElements.length; i++) 137 { 138 if (tagElements[i].className.match("delbtn")) 139 { 140 tagElements[i].setAttribute("id", "delBtn" + seq); 141 ++seq; 142 } 143 } 144 } 145 146 /* 147 * editRow: 編集ボタン該当行の内容を入力・編集またモード切り替え 148 */ 149 function editRow(obj) 150 { 151 const objTR = obj.parentNode.parentNode; 152 const rowId = objTR.sectionRowIndex; 153 const objInp = document.getElementById("txt" + rowId); 154 const objBtn = document.getElementById("edtBtn" + rowId); 155 156 if (!objInp || !objBtn) 157 return; 158 159 // モードの切り替えはボタンの値で判定 160 if (objBtn.value === "編集") 161 { 162 objInp.style.cssText = "border:none;"; 163 objInp.readOnly = false; 164 objInp.focus(); 165 objBtn.value = "確定"; 166 } 167 else 168 { 169 objInp.style.cssText = "border:none;"; 170 objInp.readOnly = true; 171 objBtn.value = "編集"; 172 } 173 } 174</script> 175</html>
このような質問フォームを作っています。
このような画面が最初に表示され、上の「あああああ」と書いてあるtextareaの内容、名前、選択した好きな食べ物の名前を、次の画面に送りたいです。
次の画面は、
PHP
1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 <meta charset="UTF-8"> 5 <title>narratica</title> 6</head> 7<body> 8<?php 9$nyuuryoku = ""; 10if (!isset($_POST['comment'])) { 11 echo '送信されていません'; 12} elseif ($_POST['comment'] === '') { 13 echo '入力されていません'; 14} 15else{ 16 $nyuuryoku = htmlspecialchars($_POST['comment']); 17} 18 19$charactors = array(); 20$selects = array(); 21 22$num = 0; 23$main = ""; 24 25if ($_SERVER["REQUEST_METHOD"] === "POST") { 26 while (true) { 27 $num++; 28 if (!isset($_POST['txt'.$num])) { 29 break; 30 } 31 $select = $_POST['select'.$num]; 32 array_push($selects, $select); 33 $name = $_POST['txt'.$num]; 34 if ($select == "主人公") { 35 $main = $name; 36 } 37 array_push($charactors, $name); 38 39 } 40} 41?> 42</body> 43</html>
このような感じです。
$_GETではなく、$_POSTで送りたいです。(書くことが長くなる恐れがあるので。)
しかし、送信ボタンを押すと、
と出てきて、うまくいきません。
どうすれば直すのか、ご教示お願いします。
回答4件
あなたの回答
tips
プレビュー