I am trying to better understand the ISSET() function. It is my understanding that when used properly, I can determine if a "submit" button was pressed or not because the function determines true or false. I have written some html code that uses the HTML Tag and HTML tag type submit. What I was trying to test was whether the ISSET function would return False while the button was not pressed and True when it was pressed.
Using Wordpress Plugin called "Woody snippets" it allows the combination of HTML and PHP in a shortcode.
Please see my code below:
I have been trying to follow a validation video on youtube = https://youtu.be/x_-HdHijmkw
I did everything line for line and initially it worked, upon refreshing the page, it did not clear all of the variables and the isset function acted as if the boolean was true. I thought it was my cache, so I cleared it. Still the ISSET funtion acts as if the boolean is true.
<?php
if (isset($_GET['fname']) && isset($_GET['lname'])) {
$fname = $_GET['fname'];
$lname = $_GET['lname'];
echo "Hello ".$fname;
}
?>
<form action='' method='get'>
First Name: <input type="text" name="fname"><br>
Last Name: <input type="text" name="lname"><br>
<input type="submit" value="Greet Me"><br>
</form>
I expected upon refresh that the isset() function and the variables used to determine true or false would be false until I entered values and pressed the button again.
Pre info: isset($a) && isset($b)
is equivalent to isset($a,$b)
isset() proofs the existence of a var, not if it is empty. Try
if ( isset($_GET['fname'],$_GET['lname'])
&& strlen($_GET['fname'])
&& strlen($_GET['lname']) { ...