How To Read If A Checkbox Is Checked In PHP? - GeeksforGeeks
Có thể bạn quan tâm
Using isset() Function
The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL. This function also checks if a declared variable, array or array key has null value, if it does, isset() returns false, it returns true in all other possible cases. This problem can be solved with the help of isset() function.
Syntax:
bool isset( $var, mixed )Description: This function accepts more than one parameters. The first parameter of this function is $var. This parameter is used to store the value of variable.
Program:
<?php if(isset($_GET['submit'])) { $var = $_GET['option1']; if(isset($var)) { echo "Option 1 submitted successfully"; } } ?> <html lang="en"> <head> <title>GeeksforGeeks Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href= "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <style> .gfg { font-size:40px; font-weight:bold; color:green; } body { text-align:center; } </style> </head> <body> <div class="container"> <div class = "gfg">GeeksforGeeks</div> <h2>Form control: checkbox</h2> <p>The form below contains one checkbox.</p> <form method="get"> <div class="checkbox"> <label><input type="checkbox" name = "option1" value="Option 1">Option 1</label> <label><button name="submit" value='true' class="btn btn-default">SUBMIT</button> </div> </form> </div> </body> </html> |
Output:
Using empty() Function
The empty() function is an inbuilt function in PHP which is used to check whether a variable is empty or not.
Syntax:
bool empty( $var )Description: This function determine whether a variable is empty or not.
Example:
<?php if(!empty($_GET['submit'])) { $var = $_GET['option1']; if(isset($var)){ echo "Option 1 submitted successfully"; } } ?> <!DOCTYPE html> <html lang="en"> <head> <title>GeeksforGeeks Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href= "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script> <style> .gfg { font-size:40px; font-weight:bold; color:green; } body { text-align:center; } </style> </head> <body> <div class="container"> <div class = "gfg">GeeksforGeeks</div> <h2>Form control: checkbox</h2> <p>The form below contains one checkbox.</p> <form method="get"> <div class="checkbox"> <label><input type="checkbox" name = "option1" value="Option 1">Option 1</label> <label><button name="submit" value="true" class="btn btn-default">SUBMIT</button> </div> </form> </div> </body> </html> |
Output:
Reference:
- http://php.net/manual/en/function.isset.php
- http://php.net/manual/en/function.empty.php
Từ khóa » Html Checkbox Php If Checked
-
How To Read If A Checkbox Is Checked In PHP? - Stack Overflow
-
Read If Checkbox Is Checked In PHP | Delft Stack
-
See If A Checkbox Is Checked In PHP | Beamtic
-
Get Checked Checkboxes Value With PHP - Makitweb
-
Handling Checkbox In A PHP Form Processor - HTML Form Guide
-
PHP: Get Values Of Multiple Checked Checkboxes - FormGet
-
How To Get Checkbox Value In Php If Checked? - Pakainfo
-
PHP Checkbox - PHP Tutorial
-
HTML Input Checked Attribute - W3Schools
-
If Checkbox Is Checked Do Something - PHP Tutorial [WordPress]
-
How To Display Text When A Checkbox Is Checked - W3Schools
-
Verifying Checkboxes Are Checked With PHP - WillMaster
-
How To Check If Checkbox Is Checked? - Laracasts
-
How To Get Checked Checkbox Value In Php? - Lotus