Detect which button is clicked in a form
Moderator: General Moderators
Detect which button is clicked in a form
Hi guys
I am trying to perform a function like this:
I have used php to create "delete" button with each row of record, though I am not sure whether I am doing the right thing.
Then it sends the form to another php page to process the query. My question is on that page, how can know which delete button of which record is clicked ?
any way to do that?
thanks
I am trying to perform a function like this:
I have used php to create "delete" button with each row of record, though I am not sure whether I am doing the right thing.
Then it sends the form to another php page to process the query. My question is on that page, how can know which delete button of which record is clicked ?
any way to do that?
thanks
-
thinsoldier
- Forum Contributor
- Posts: 367
- Joined: Fri Jul 20, 2007 11:29 am
- Contact:
Re: Detect which button is clicked in a form
I'd help but... this isn't hard.
Go find a tutorial.
All I'll say is
Go find a tutorial.
All I'll say is
Code: Select all
<pre>
<?php
print_r($_POST);
?>
</pre>
Warning: I have no idea what I'm talking about.
Re: Detect which button is clicked in a form
is this is right way to do it?thinsoldier wrote:I'd help but... this isn't hard.
Go find a tutorial.
All I'll say is
Code: Select all
<pre> <?php print_r($_POST); ?> </pre>
I used a link
Code: Select all
<a href='register.php?id={$_POST}'>Add</a>Thanks for help
Re: Detect which button is clicked in a form
You can pass the id in each row of record.Like:
Where ID uniquely identifies the record.
Code: Select all
<a href='deletePage.php?id=ID'>Delete</a>Re: Detect which button is clicked in a form
If you want to get a clearer idea of what is going on, set up a page with something like the following ...
Give it a run and you should see the solution you need to implement. If you need more help, feel free to ask.
Hope this helps.
[EDIT] - makes more sense when the buttons have different indexes.
Code: Select all
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
print_r($_POST);
?>
<pre>
It would appear you chose to delete item number <?php echo key($_POST['delete']); ?>
</pre>
<?php
}
?>
<form method="post" action="this.php">
<input type="submit" name="delete[1]" value="Delete">
<input type="submit" name="delete[2]" value="Delete">
<input type="submit" name="delete[3]" value="Delete">
</form>
Hope this helps.
[EDIT] - makes more sense when the buttons have different indexes.
Last edited by Stryks on Thu Sep 18, 2008 11:17 pm, edited 1 time in total.
Re: Detect which button is clicked in a form
The method shown by pcoder is totally valid also. It's just my preference not to use POST and GET together where possible.
But it's all valid so it's all good.

But it's all valid so it's all good.
Re: Detect which button is clicked in a form
I would use checkbuttons and then one submit button. It's then easy to add a "check all" button for more usability.morris520 wrote:Hi guys
I am trying to perform a function like this:
I have used php to create "delete" button with each row of record, though I am not sure whether I am doing the right thing.
Then it sends the form to another php page to process the query. My question is on that page, how can know which delete button of which record is clicked ?
any way to do that?
thanks
Re: Detect which button is clicked in a form
Stryks wrote:If you want to get a clearer idea of what is going on, set up a page with something like the following ...Give it a run and you should see the solution you need to implement. If you need more help, feel free to ask.Code: Select all
<?php if($_SERVER['REQUEST_METHOD'] == 'POST') { print_r($_POST); ?> <pre> It would appear you chose to delete item number <?php echo key($_POST['delete']); ?> </pre> <?php } ?> <form method="post" action="this.php"> <input type="submit" name="delete[1]" value="Delete"> <input type="submit" name="delete[2]" value="Delete"> <input type="submit" name="delete[3]" value="Delete"> </form>
Hope this helps.
[EDIT] - makes more sense when the buttons have different indexes.
Yep.. This works perfectly. This is excatly what I try to do.
Also, the get method is more easier to understand.
Guys, thanks for all of your help