I have a with 3 tags as given below;
JavaScript
x
4
1
<input type="name" class="form-control" id="name" placeholder="Enter name" name="name[]">
2
<input type="text" class="form-control" id="phone" placeholder="Enter phone" name="phone[]">
3
<input type="file" name="Image[]" id="image" multiple />
4
I enter record of 2 persons. I select 2 images for 1st person and 3 images for 2nd person. When I submit form then I receive data as following;
JavaScript
1
26
26
1
Array
2
(
3
[name] => Array
4
(
5
[0] => Mr A
6
[1] => Mr B
7
)
8
9
[phone] => Array
10
(
11
[0] => 1234567
12
[1] => 9876543
13
)
14
15
[Image] => Array
16
(
17
[0] => 1 (1).png
18
[1] => 1 (2).png
19
[2] => 1 (3).png
20
[3] => 1 (4).png
21
[4] => 1 (5).png
22
)
23
24
[submit] => Submit
25
)
26
Problem is, How can I identify which images belongs to which person. I need data as separate set for each person as following
JavaScript
1
32
32
1
Array
2
(
3
[name] => Array
4
(
5
[0] => Mr A
6
[1] => Mr B
7
)
8
9
[phone] => Array
10
(
11
[0] => 1234567
12
[1] => 9876543
13
)
14
15
[Image] => Array
16
(
17
[0] => Array
18
(
19
[0] => 1 (1).png
20
[1] => 1 (2).png
21
)
22
[1] => Array
23
(
24
[0] => 1 (3).png
25
[1] => 1 (4).png
26
[2] => 1 (5).png
27
)
28
)
29
30
[submit] => Submit
31
)
32
Please help in this context
Advertisement
Answer
I have solved my problem myself. We could not send data as separate group unless we change name attribute. I have fixed by changing the name onClick
JavaScript
1
2
1
<input type="file" name="image[1][]" id="" onchange="countFiles()" multiple />
2
JQuery
JavaScript
1
5
1
function countFiles(){
2
var n = $(':input[type=file]').length; //counts input type file tags
3
$(event.currentTarget).attr('name', 'image['+n+'][]'); //changes name
4
}
5