Way to check if submit button/s haven't been clicked
Posted: Tue Feb 19, 2013 4:33 am
I have a form with two submit buttons and i know how to check whether the buttons have been clicked; but how do you check if neither of the buttons have been clicked ?
The page will have two different functions depending on the button clicked and for no button clicked a message will be displayed. I did a var_dump($_POST) on the page if no button is clicked and i get this result:
My thinking, when determining whether a button has been clicked, is to start with this code:
In the else statement i'll have two if statements, each one checking for the click of a button.
Is this a valid approach? There might be additional functions for this page in future so i want the code to be as flexible as possible.
The page will have two different functions depending on the button clicked and for no button clicked a message will be displayed. I did a var_dump($_POST) on the page if no button is clicked and i get this result:
Code: Select all
array(0) { }
Code: Select all
//
if (count($_POST) == 0) {
/*
default message if page is accessed directly
*/
}
else {
/*
check which button has been clicked.
*/
}
Is this a valid approach? There might be additional functions for this page in future so i want the code to be as flexible as possible.