HTML form action with php
627
<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 useaction="admin-process.php"
. But I don't understanding what is "?" after the php in this case, and the meaning of on submit.
Answer
Solution:
?
at the end ofadmin-process.php?action=cat_insert
denotes where the url parameters begin. This allows you to pass information from one page to the next using theGET
method. This is in addition to the parameters passed through toadmin-process.php
by the form which use thePOST
method.The
GET
method is useful for passing a reasonable amount of non sensitive data between pages, while thePOST
method has less limitations and is best for more sensitive data.In this instance you could obtain the value of
action
onadmin-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.