Change language

How can I check form submission in PHP?

Syntax:
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:

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method