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.

370

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.

TheGET 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 ofaction 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.

People are also looking for solutions to the problem: php - How to add and remove table rows using checkboxes

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.