I’ve got the following bit of code to check if a form with multiple fields are correctly filled. The problem is, is that it doesn’t concat the strings properly.
Below is some code of the code:
if(strlen($name) < 2 || strlen($email) < 6 || strlen($subject) < 5 || strlen($message) < 15){
$alert = "There are some problems: \n";
if(strlen($name) < 2){
$alert . "Name is too short \n";
}
if(strlen($email) < 6){
$alert . "email is too short \n";
}
if(strlen($subject) < 5){
$alert . "The subject is too short \n";
}
if(strlen($message) < 15){
$alert . "Your message is too short \n";
}
$alert . "Please fill in te fields correctly";
echo $alert;
?>
<script>
alert("<?= $alert ?>");
</script>
<?php
}
else { ... } ?>
If i place an echo inside each if statement it shows that it triggers, but in the end all that get’s alerted and printed by the echo is “There are some problems:”
Why doesn’t the alert string gets properly concatinated? I tried removing the \n in each sentence but that didn’t work either.
You should be doing
$alert .= "something", not just$alert . "something".