Log in

View Full Version : how to tell from which button send to the script?



writeman
03-19-2007, 06:46 AM
hi All
I have three input type button which do some function.
If I press "save" or "del" button, they post data to the remote machine's php script.
How can my php script tell from which button send to it?

<form action="b01svr.php" OnSubmit="return isEmpty(this)" method="POST">
.......................
<tr><td><input type="reset" value="clear"></td></tr>
<tr><td><input type="submit" value="save"></td></tr>
<tr><td><input type="submit" value="del"></td></tr>
</form>

codeexploiter
03-19-2007, 08:25 AM
While creating the submit button make sure that you give each button a unique name like the following


<input type="submit" name="save" value="Save">
<input type="submit" value="Del" name="del">


In your PHP page you can just have code like the following



$save = $_POST['save'];
$del = $_POST['del'];


If you put the above code in your PHP code you can find out which button has been pressed by the user.

If the user clicked save button then you'll get the value you've mentioned in the value attribute of save <input> tag in this case it is Save.

If the user clicked del button then you'll get the value you've mentioned in the value attribute of del <input> tag in this case it is Del.

I think the technique is clear now so based on the value stored in the $save and $del you can identify the button press.

writeman
03-21-2007, 05:13 AM
Thanks codeexploiter
I got the way to send and receive data between client and server.
Thanks.