STE
STE

Reputation: 666

Distinguish which on of the buttons with the same value was pressed

I'm trying to write an admin panel for a website. The functionality I want to code is simple: there will be a list of projects and next to the project's name there will be a button called 'edit'. The button will lead the user to another page where he can edit that specific project.

What confuses me is the fact that I can't identify which button was pressed unless I check each one of the buttons specifically (am i right?). It would help if all the buttons have the same name and different value rather than different names and same value.

So is there a way to actually tell which project's button was pressed?

Thanks in advance

Upvotes: 0

Views: 56

Answers (1)

dev-null-dweller
dev-null-dweller

Reputation: 29462

Most browsers will send value of value attribute of button element:

<button type="submit" name="id" value="123">Edit</button>

But if you need to support older versions of IE, you might use arraylike name

<input type="submit" name="id[123]" value="Edit" />

And access it in php:

<?php

$id = key($_POST['id']);

Upvotes: 1

Related Questions