Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mick79's avatar

Update multiple fields from a checkbox list

OK... this should be really simple. But I have a newborn and I my head is fried (that's my excuse and I'm sticking to it)

I have a list of music tracks and right now you need to update each one individually. Obviously the right thing to do here is allow users to select multiple tracks and then, for example, DELETE.

I also want them to be able to change track names right from this ui.

It looks like this (a picture speaks a thousand words): https://tinyurl.com/yebytngk

The problem I'm facing is when I submit I get an array of checked rows, and array of the tracknames.

I'm stuck on how to update the track names as if I say

Where track name = "x" set as "y"

then that could fail as they might have tracks with the same name (unlikely but they might)

So I'd need the track ID and the track name, but they are being passed in separate arrays.

Someone tell me how dumb I'm being please :-)

0 likes
2 replies
kaplay's avatar
kaplay
Best Answer
Level 33

Hi bro, i think you look something like that

Song id is 0
<input type="checkbox" name="songs[0][id]" />
<input type="text" name="songs[0][name]" value="new name for song 1" />

Song id is 1
<input type="checkbox" name="songs[1][id]" />
<input type="text" name="songs[1][name]" value="new name for song 2" />

When you post that form, you will get

public function update(Request $request)
{
	foreach($request->songs as $song) {
		$songId = $song['id'];
		$songName = $song['name'];
		//Now if you want you can find and delete or update
	}
}
Mick79's avatar

@kaplay This is awesome insight. Thank you, I'll give it a bash.

Please or to participate in this conversation.