Reputation: 1800
I am using this code in my *.php
file
$check = $_POST['dati'];
if (strlen($check) != 0) {
// calculations
}
else {
echo "contact me at <a href='mailto:myemail'></a>";
}
The dati
inside that POST is the name attribute of an input field. If the input has a length = 0, that echo must be displayed.
I have the same code in another part of my server and it works perfectly. I'm having troubles here because when the length of dati
is 0, the script makes the calculations instead of showing the echo.
<input name="dati" id="dati" style="width:310px" type="text">
This is the code of the input. Any ideas?
Upvotes: 1
Views: 2876
Reputation: 74217
In the following example, if field is left blank, echo'ed message is "sorry".
If text entered, then Email link appears. TESTED
<?php
if(isset($_POST['submit']))
$check = $_POST['dati'];
if (strlen($check) == 0) {
echo "Sorry";
}
else {
echo "Contact me at <a href='mailto:myemail'>LINK</a>";
}
?>
FORM
<form method="post" action="your_handler.php">
<input name="dati" id="dati" style="width:310px" type="text">
<input type="submit" name="submit" value="Submit">
</form>
Upvotes: 0
Reputation: 11845
You code works well as you can see here: http://codepad.org/fCvlokOJ and here http://codepad.org/t2TvFozt
<?php
$_POST['dati']= "text";
if (strlen($_POST['dati']) != 0) {
echo" calculations";
}
else {
echo "contact me at <a href='mailto:myemail'></a>";
}
Upvotes: 2