Hugo Hugo - 3 months ago 60
PHP Question

HTML form action with php

<form id="cat_insert" method="POST" action="admin-process.php?action=cat_insert" onsubmit="return false;">

I found this format of HTML form in the sample code provided by my teacher. I know apply php code after submitting the form would use
. But I don't understanding what is "?" after the php in this case, and the meaning of on submit.


? at the end of admin-process.php?action=cat_insert denotes where the url parameters begin. This allows you to pass information from one page to the next using the GET method. This is in addition to the parameters passed through to admin-process.php by the form which use the POST method.

The GET method is useful for passing a reasonable amount of non sensitive data between pages, while the POST method has less limitations and is best for more sensitive data.

In this instance you could obtain the value of action on admin-process.php by using either $_GET['action'] or $_REQUEST['action'] ($_REQUEST includes the contents of $_GET, $_POST and $_COOKIE).

onsubmit="return false;" is JavaScript and is used to suppress the default behaviour of the form when it is submitted, this will stop the form from submitting (if JavaScript is enabled). This is likely because some other action is taken by JavaScript (for example validation), exactly what this is for in this case is unclear given the snippet of code.