if (! empty ($_ POST)) if (isset ($_ POST [’submit’]))Use these two statements to check if the form was submitted successfully or not.Note.Use a local server like WAMP or XAMPP to run this program.Method-1:
Step 1:Create a simple form using HTML and CSS.In this step, first create an HTML form, to check if it’s sent correctly or not. So it’s just basic programming to create a form using the form tag. Use the action attribute to send a request to another PHP file. The method is used to retrieve information or post information entered into a form.
<
html
>
<
head
>
<
title
> Form < /
title
>
< /
head
>
<
body
>
<
form
action
=
"get-method.php"
method
=
"post"
>
Author: <
input
type
=
"text"
name
=
"author "
placeholder
=
"Author’s Name"
/ >
<
br
> <
br
>
Number of published Article: <
input
type
=
"number"
name
=
"num_article"
placeholder
=
"Published Article"
/ >
<
br
> <
br
>
<
input
type
=
"submit"
name
=
"submit"
value
=
"Submit"
>
< /
form
>
< /
body
>
< /
html
>
Output: Step 2:Create a PHP file for the POST methodUse the isset() method in PHP to check if the form was submitted successfully. In your code, use the isset() function to test the $_POST [’ submit ’] method. Remember, instead of confirming, provide the name of the submit button. After clicking on the submit button, this action will act as a POST method.
if
(isset (
$_ POST
[
’ submit’
])) {
echo
"GeeksforGeeks"
;
}
?>
Final output to localhost: Method 2:
Without using a separate PHP file:Without using a separate file, HTML code is written, in which you can specify the PHP action code in the script tag, as we did in this demo. Both of these codes display the same output, but their implementation is different.Example :
< title > Form < / title >
< / head >
< form action =
" get-method.php "
method =
" post "
>
Author: " text "
name =
"author"
placeholder =
" Author’s Name "
/ >
Number of published Article: " number "
name =
"num_article"
placeholder =
" Published Article "
/ >
" submit "
name =
" submit "
value =
" Submit "
>
< / form >
< / html >
Output to local host: