質問編集履歴
4
誤字
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -12,94 +12,7 @@
|
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
### 該当のソースコード
|
|
15
|
-
```php
|
|
16
|
-
<!DOCTYPE html>
|
|
17
15
|
|
|
18
|
-
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
|
19
|
-
<head>
|
|
20
|
-
<meta charset="utf-8" />
|
|
21
|
-
<title>フォームを増やす</title>
|
|
22
|
-
|
|
23
|
-
</head>
|
|
24
|
-
<style>
|
|
25
|
-
|
|
26
|
-
</style>
|
|
27
|
-
<body>
|
|
28
|
-
<form id="frm" action="createpage.php" method="POST" enctype="multipart/form-data">
|
|
29
|
-
<div class="form-group">
|
|
30
|
-
<label for="comment">Title:</label>
|
|
31
|
-
<textarea class="form-control" rows="2" id="title" minlength="1" placeholder="Mタイトルを記入してください。" name="main" required></textarea>
|
|
32
|
-
|
|
33
|
-
<label for="comment">Comment:</label>
|
|
34
|
-
<textarea class="form-control" rows="10" id="comment" maxlength="1000000" placeholder="(改行はそのまま表示されます。)" name="comment" required></textarea>
|
|
35
|
-
</div>
|
|
36
|
-
<p>以下、ファイルのアップロード。<p>
|
|
37
|
-
<div id="file-container">
|
|
38
|
-
</div>
|
|
39
|
-
<input id="add-file-input" type="button" value="追加">
|
|
40
|
-
<input class="btn btn-success" type="submit" value="送信"></form>
|
|
41
|
-
<script>
|
|
42
|
-
/**
|
|
43
|
-
* とりあえずフォームを増減させるための記述
|
|
44
|
-
*/
|
|
45
|
-
const FileInput = function () {
|
|
46
|
-
// 増減する一連のINPUTタグの格納場所
|
|
47
|
-
const container = document.querySelector('#file-container')
|
|
48
|
-
|
|
49
|
-
// 別名で管理する必要があるのでINDEX番号で管理する
|
|
50
|
-
let number = 0
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* タイトル、説明、ファイルアップロードINPUTの塊を作るプライベートメソッド
|
|
54
|
-
*/
|
|
55
|
-
const createInputs = function () {
|
|
56
|
-
const i = number
|
|
57
|
-
number = number + 1
|
|
58
|
-
|
|
59
|
-
// 子コンテナのDIVタグを作る
|
|
60
|
-
const inputContainer = document.createElement('div')
|
|
61
|
-
// あとでデザインしやすいようにクラス名を設定しておく
|
|
62
|
-
inputContainer.className = 'input-container'
|
|
63
|
-
|
|
64
|
-
// 子コンテナの中身を文字列で設定しておく(テンプレートリテラルで作ると楽)
|
|
65
|
-
inputContainer.innerHTML = `
|
|
66
|
-
title: <input type="text" name="title[${i}]"><br>
|
|
67
|
-
description: <textarea name="desc[${i}]"></textarea><br>
|
|
68
|
-
file: <input type="file" name="file[${i}]" accept=".zip ,.rar ,.jpeg ,.png ,.jpg ,.webp "><br>
|
|
69
|
-
<input type="button" class="delete-button" value="削除">
|
|
70
|
-
`
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
inputContainer.querySelector('.delete-button').addEventListener('click', function () {
|
|
74
|
-
container.removeChild(inputContainer)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
container.appendChild(inputContainer)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
add: createInputs
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// インスタンス作成
|
|
88
|
-
const file = FileInput()
|
|
89
|
-
|
|
90
|
-
document.querySelector('#add-file-input').addEventListener('click', file.add)
|
|
91
|
-
</script>
|
|
92
|
-
<!-- <form method="get" action="">
|
|
93
|
-
<button type='submit' name='action' value='add'>追加</button>
|
|
94
|
-
<button type='submit' name='action' value='del'>削除</button>
|
|
95
|
-
</form>
|
|
96
|
-
-->
|
|
97
|
-
|
|
98
|
-
</body>
|
|
99
|
-
</html>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
```
|
|
103
16
|
```php
|
|
104
17
|
|
|
105
18
|
//書き込みオリジナルファイル読み込み
|
3
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
<head>
|
|
20
20
|
<meta charset="utf-8" />
|
|
21
21
|
<title>フォームを増やす</title>
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
</head>
|
|
24
24
|
<style>
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
</style>
|
|
27
27
|
<body>
|
|
28
28
|
<form id="frm" action="createpage.php" method="POST" enctype="multipart/form-data">
|
|
@@ -148,10 +148,10 @@
|
|
|
148
148
|
<meta charset="utf-8">
|
|
149
149
|
<title>たいとる</title>
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
|
|
152
152
|
</head>
|
|
153
153
|
<style>
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
</style>
|
|
156
156
|
<body>
|
|
157
157
|
<a href="https://teratail.com/questions/14413">参考</a>
|
2
修正
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -154,4 +154,13 @@
|
|
|
154
154
|
<?php include('../../resetcss.php');?>
|
|
155
155
|
</style>
|
|
156
156
|
<body>
|
|
157
|
-
<a href="https://teratail.com/questions/14413">参考</a>
|
|
157
|
+
<a href="https://teratail.com/questions/14413">参考</a>
|
|
158
|
+
|
|
159
|
+
<h1>たいとるについて</h1>
|
|
160
|
+
<p>説明</p>
|
|
161
|
+
|
|
162
|
+
<p>ファイル</p>
|
|
163
|
+
|
|
164
|
+
</body>
|
|
165
|
+
</html>
|
|
166
|
+
```
|
1
全てのコードを記述
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -12,7 +12,94 @@
|
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
### 該当のソースコード
|
|
15
|
+
```php
|
|
16
|
+
<!DOCTYPE html>
|
|
15
17
|
|
|
18
|
+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
|
19
|
+
<head>
|
|
20
|
+
<meta charset="utf-8" />
|
|
21
|
+
<title>フォームを増やす</title>
|
|
22
|
+
<?php include('library.php');?>
|
|
23
|
+
</head>
|
|
24
|
+
<style>
|
|
25
|
+
<?php include('resetcss.php');?>
|
|
26
|
+
</style>
|
|
27
|
+
<body>
|
|
28
|
+
<form id="frm" action="createpage.php" method="POST" enctype="multipart/form-data">
|
|
29
|
+
<div class="form-group">
|
|
30
|
+
<label for="comment">Title:</label>
|
|
31
|
+
<textarea class="form-control" rows="2" id="title" minlength="1" placeholder="Mタイトルを記入してください。" name="main" required></textarea>
|
|
32
|
+
|
|
33
|
+
<label for="comment">Comment:</label>
|
|
34
|
+
<textarea class="form-control" rows="10" id="comment" maxlength="1000000" placeholder="(改行はそのまま表示されます。)" name="comment" required></textarea>
|
|
35
|
+
</div>
|
|
36
|
+
<p>以下、ファイルのアップロード。<p>
|
|
37
|
+
<div id="file-container">
|
|
38
|
+
</div>
|
|
39
|
+
<input id="add-file-input" type="button" value="追加">
|
|
40
|
+
<input class="btn btn-success" type="submit" value="送信"></form>
|
|
41
|
+
<script>
|
|
42
|
+
/**
|
|
43
|
+
* とりあえずフォームを増減させるための記述
|
|
44
|
+
*/
|
|
45
|
+
const FileInput = function () {
|
|
46
|
+
// 増減する一連のINPUTタグの格納場所
|
|
47
|
+
const container = document.querySelector('#file-container')
|
|
48
|
+
|
|
49
|
+
// 別名で管理する必要があるのでINDEX番号で管理する
|
|
50
|
+
let number = 0
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* タイトル、説明、ファイルアップロードINPUTの塊を作るプライベートメソッド
|
|
54
|
+
*/
|
|
55
|
+
const createInputs = function () {
|
|
56
|
+
const i = number
|
|
57
|
+
number = number + 1
|
|
58
|
+
|
|
59
|
+
// 子コンテナのDIVタグを作る
|
|
60
|
+
const inputContainer = document.createElement('div')
|
|
61
|
+
// あとでデザインしやすいようにクラス名を設定しておく
|
|
62
|
+
inputContainer.className = 'input-container'
|
|
63
|
+
|
|
64
|
+
// 子コンテナの中身を文字列で設定しておく(テンプレートリテラルで作ると楽)
|
|
65
|
+
inputContainer.innerHTML = `
|
|
66
|
+
title: <input type="text" name="title[${i}]"><br>
|
|
67
|
+
description: <textarea name="desc[${i}]"></textarea><br>
|
|
68
|
+
file: <input type="file" name="file[${i}]" accept=".zip ,.rar ,.jpeg ,.png ,.jpg ,.webp "><br>
|
|
69
|
+
<input type="button" class="delete-button" value="削除">
|
|
70
|
+
`
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
inputContainer.querySelector('.delete-button').addEventListener('click', function () {
|
|
74
|
+
container.removeChild(inputContainer)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
container.appendChild(inputContainer)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
add: createInputs
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// インスタンス作成
|
|
88
|
+
const file = FileInput()
|
|
89
|
+
|
|
90
|
+
document.querySelector('#add-file-input').addEventListener('click', file.add)
|
|
91
|
+
</script>
|
|
92
|
+
<!-- <form method="get" action="">
|
|
93
|
+
<button type='submit' name='action' value='add'>追加</button>
|
|
94
|
+
<button type='submit' name='action' value='del'>削除</button>
|
|
95
|
+
</form>
|
|
96
|
+
-->
|
|
97
|
+
|
|
98
|
+
</body>
|
|
99
|
+
</html>
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
```
|
|
16
103
|
```php
|
|
17
104
|
|
|
18
105
|
//書き込みオリジナルファイル読み込み
|
|
@@ -52,4 +139,19 @@
|
|
|
52
139
|
print '<a href="'.$fileName.'">'.$fileName. '</a>'."をのリンク。<br/>\n";
|
|
53
140
|
|
|
54
141
|
var_dump($_POST['title'],$_POST['desc'],$_FILES['file']['name']);
|
|
55
|
-
```
|
|
142
|
+
```
|
|
143
|
+
```php
|
|
144
|
+
org.php
|
|
145
|
+
<!DOCTYPE html>
|
|
146
|
+
<html>
|
|
147
|
+
<head>
|
|
148
|
+
<meta charset="utf-8">
|
|
149
|
+
<title>たいとる</title>
|
|
150
|
+
|
|
151
|
+
<?php include('../../library.php');?>
|
|
152
|
+
</head>
|
|
153
|
+
<style>
|
|
154
|
+
<?php include('../../resetcss.php');?>
|
|
155
|
+
</style>
|
|
156
|
+
<body>
|
|
157
|
+
<a href="https://teratail.com/questions/14413">参考</a>
|