Please give the form an action!
And you have to name the submit button submit:
<input type="submit" name="submit" id="submit" value="Submit" />
Otherwise isset()
will return false.
Question
I got a very simple problem and I've searched for it for hours. But I just don't fix my error... I try to get the value of my textbox (I know, there are lots of posts but no one of them could've helped me).
I got this HTML
code:
<form action="" method="post">
<input type="text" id="address" name="address" placeholder="Enter your zip code" style="width:250px;" />
<input type="submit" id="submit" value="Submit" />
</form>
And this is PHP
code #1 I tried:
<?php
$textboxValue = $_POST['address'];
echo $textboxValue;
?>
This doesn't work and I don't know why. After trying this, I found another code:
<?php
if(isset($_POST['submit'])){
$textboxValue = $_POST['address'];
echo $textboxValue;
}
?>
This doesn't seem to work. Like the other one.
Is there an error or why is the $textboxValue
not displayed when I call it with echo
?
Solution
Please give the form an action!
And you have to name the submit button submit:
<input type="submit" name="submit" id="submit" value="Submit" />
Otherwise isset()
will return false.
OTHER TIPS
I found the error. In my file I had a return = false;
so he couldn't execute the $_POST
method. But thanks for all your help :)