gravityforms-repeater
gravityforms-repeater copied to clipboard
Multiple time fields in repeater are stored incorrectly
I need to use multiple time inputs in a repeater, and it is storing the data incorrectly.
Example of how it is currently stored:
a:2:{
i:1;a:3:{
i:21;a:4:{i:0;s:2:"14";i:1;s:2:"50";i:2;s:2:"18";i:3;s:2:"24";}
i:22;a:1:{i:0;s:6:"test 1";}
i:23;a:4:{i:0;s:2:"13";i:1;s:2:"20";i:2;s:2:"14";i:3;s:2:"55";}
}
i:2;a:3:{
i:21;a:0:{}
i:22;a:1:{i:0;s:6:"test 2";}
i:23;a:0:{}
}
}
The line i:23;a:4:{i:0;s:2:"13";i:1;s:2:"20";i:2;s:2:"14";i:3;s:2:"55";} should be paired with the line i:22;a:1:{i:0;s:6:"test 2";}
Each row is meant to have a text value, and two times, as you can see the times are being concatenated for some reason, and combined incorrectly.
The resulting display in the form entry tab also looks totally wrong (see attached screenshot)

OK, the issue is that time fields (and multiple select list for example) use an array name value eg name="input_1[]"
The repeat is changing the ID and Name attributes correctly, but for some reason, anything with an array name is having its name attribute re-written to always have the repeatID as 1, no matter how many times you add a new row.
Annoyingly, in the code, the name is being created correctly, eg repeatID 2 for the 2nd row, but in the DOM it is incorrect and I cannot figure out why.
Any luck on this? I have the same issue with multiselect
I had to fix the core code of the repeater when it comes to storing dates. I'll dig out the fix later and post it here.
The issue was in JS. Select didn't get proper name & id attributes. All repeated fields had name xx-1-1[]
I can't remember what I fixed exactly. I think I tried to fix the JS for the date fields but gave up due to the code being a mess (not very well commented!) so I think I fixed it on the point of entering the data into the DB.
Sorry about that @paulcanning ! This started out as a small project for clients that I wasn't going to release but then decided to release it. It was my very first GitHub project!
@kodie lack of comments is just a reason to dig deeper into the code (and a bit more time-taking) The plugin is very useful. Thanks.
I agree, this plugin is very useful, since Gravity Forms still does not repeater in core yet.