HTML:
<form name="myform" action="process.php" method="POST">
<input type="hidden" name="check_submit" value="1" />
<!-- ........ -->
</form>
PHP:
if (array_key_exists('check_submit', $_POST)) {....}
Why can array_key_exists('check_submit', $_POST) check whether the form was submitted?
I’ve seen isset($_POST['...']) used before, but not this.
if i don’t do this array_key_exists(‘check_submit’, $_POST) decision., what may happen.
check_submitis a field in your form, so when you submit the form, that field is available in thePOSTdata.PHP places incoming
POST-method form data into the$_POSTsuperglobal array, and your code determines whether thecheck_submitfield can be found in that array.Indeed, it’s quite similar to
isset($_POST['check_submit']), in that it checks whether such an element exists in$_POST. It’s just taking a slightly different approach.If you did not submit the form, then of course there is no form data.