回答編集履歴
1
tuiki
test
CHANGED
@@ -35,3 +35,45 @@
|
|
35
35
|
</form>
|
36
36
|
|
37
37
|
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
nameを工夫できるならこうするとサーバー側でデータが取り出しやすいかもしれません
|
42
|
+
|
43
|
+
```javascript
|
44
|
+
|
45
|
+
<script>
|
46
|
+
|
47
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
48
|
+
|
49
|
+
document.querySelector('form').addEventListener('formdata',(e)=>{
|
50
|
+
|
51
|
+
e.target.querySelectorAll('[name$="[value]"]').forEach(x=>{
|
52
|
+
|
53
|
+
Object.entries({...x.dataset}).forEach(y=>{
|
54
|
+
|
55
|
+
const name=x.name.replace(/[value]$/,'')+`[${y[0]}]`;
|
56
|
+
|
57
|
+
e.formData.append(name,y[1]);;
|
58
|
+
|
59
|
+
});
|
60
|
+
|
61
|
+
});
|
62
|
+
|
63
|
+
});
|
64
|
+
|
65
|
+
});
|
66
|
+
|
67
|
+
</script>
|
68
|
+
|
69
|
+
<form>
|
70
|
+
|
71
|
+
<input type="text" name="hoge[value]" data-color="red" data-size="18px" value="山田">
|
72
|
+
|
73
|
+
<input type="text" name="fuga[value]" data-color="blue" data-size="12px" value="鈴木">
|
74
|
+
|
75
|
+
<input type="submit" value="send">
|
76
|
+
|
77
|
+
</form>
|
78
|
+
|
79
|
+
```
|