I am designing a PhP application for my project and i want to include a "save,save & new, save & close" function in my forms. all of them are submit buttons. how do i determine which one was clicked?
Asked
Active
Viewed 164 times
0
-
you can distinct it by its name... – user1844933 Feb 26 '14 at 07:21
-
A straight [**`answer`**](http://stackoverflow.com/a/8425337/1003917) – Shankar Narayana Damodaran Feb 26 '14 at 07:22
2 Answers
2
Give them different names and then in PHP check which name is set
HTML
<input type="submit" name="save" value="Save" />
<input type="submit" name="savenew" value="Save & new" />
PHP
if (isset($_POST['save'])) {
// save button
}
elseif(isset($_POST['savenew']))
{
// save & new
}
etc.

Hanky Panky
- 46,730
- 8
- 72
- 95
0
Or you can use switch case for this :
switch($_POST['name']){
case 'Save':
echo "do code here ";
break;
case 'Save & new':
echo "do code here" ;
break;
}

sismaster
- 181
- 1
- 13