If isset $_POST
Most form inputs are always set, even if not filled up, so you must check for the emptiness too.
Since !empty()
is already checks for both, you can use this:
if (!empty($_POST["mail"])) {
echo "Yes, mail is set";
} else {
echo "No, mail is not set";
}
Php if($_POST) vs if(isset($_POST))
isset
determine if a variable is set and is not NULL. $_POST
will always be set and will always be an array.
Without isset
you are just testing if the value is truthy. An empty array (which $_POST
will be if you aren't posting any data) will not be truthy.
php if isset post and else post
You can do something like:
if (isset($_POST['submit']))
{
// do something here
}
elseif (isset($_POST['cancel']))
{
// redirect here
}
if(isset($_POST['submit'])) coding form action is not working
When you want to pass data from form to your php script, you have to remember that the name attribute is assigned for that data to find in php script.
<button type="submit" class="btn btn-info">Submit</button>
In your button you are not assigned the name attribute. So after post method in php script isset($_POST['submit']) does not find any submit attribute. So it returns false.
<button type="submit" class="btn btn-info" name="submit" value="submit" >Submit</button>
So you have to use this line for button.
if (isset($_post['submit'])) is not working
Replace
<input type="submit" name="Submit" value="Submit" />
with
<input type="submit" name="submit" value="submit" />
Related Topics
Prevent Back Button from Showing Post Confirmation Alert
Reliable User Browser Detection With PHP
How to List All Months Between Two Dates
Override PHP Base Dependency in Composer
PHP Convert String to Hex and Hex to String
PHP Array to Json Array Using Json_Encode();
Opening/Closing Tags & Performance
PHP Sort Array by Two Field Values
Implode an Array With ", " and Add "And " Before the Last Item
Include PHP Inside JavaScript (.Js) Files
Disable Warnings When Loading Non-well-formed HTML by Domdocument (PHP)
Http Headers For File Downloads