I want to make this form where people can send a email to me. I've done this before but this time it won't post... I won't get a error message or anything like that. Even my custom made error messages won't show up.
<?php
$err = "<br/>";
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if (!empty($name) && !empty($email) && !empty($message)) {
if (strstr($name, " ")) {
if(strlen($email) >=5 && strstr($email, "@") && strstr($email, ".")) {
} else {
$err = "<p style='color:#b30000'>Fill in a valid email!</p>";
}
} else {
$err = "<p style='color:#b30000'>Fill in a valid name!</p>";
}
} else {
$err = "<p style='color:#b30000'>Fill in all the fields!</p>";
}
} else {$name = ''; $email = ''; $message = '';}
echo $err . "
<form id='form' action='#form' method='post'>
<p>Full Name:</p>
<input class='input' type='text' name='name' placeholder=' Dirk Vondiek' value=". $name . ">
<p>E-Mail:</p>
<input class='input' type='text' name='email' placeholder=' example@domain.com' value=". $email . ">
<p>Your Message:</p>
<textarea class='textarea' name='message' placeholder=' Can you pls add me on steam?'>". $message ."</textarea>
<center><input class='submit' type='submit' name'submit' value='Send'></input></center>
</form>
"
?>
action='#form'
, it's invalid for an action syntax, so change that to action=""
or action="handler.php"
if you later decide to use two seperate files.
Edit for above: After testing for myself, that does indeed work, but the major culprit here is that you have a typo here name'submit'
and your conditional statementif (isset($_POST['submit'])) {...}
will never happen because of it.
So modify it to read as name='submit'
.
You also have </input>
you can safely get rid of it, it's not a valid closing tag.
And you forgot to close this statement (but in testing this didn't throw me an error and I find that rather a bit bizarre).
</form>
"
?>
So.
</form>
";
?>
That alone with error reporting would have thrown you something about it.
Nota:
However, if you have more code below the </form>"
line, then you will get a parse error such as:
(Nota: I added an echo "Testing";
for this example error) but will throw you a parse error related to what you may be using:
Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';'
As you mention in your question that it's meant to send mail with, but that wasn't included in your original post.
If you do have more code below that line and inside the same <?php ...?>
tags, then you will need to close off that statement as stated in my answer.
For example.
This will throw a parse error:
</form>
"
mail();
?>
This won't throw an error (valid) so it needs to be closed (mail()
is just a fill-in example here).
</form>
";
mail();
?>
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code
Sidenote: Displaying errors should only be done in staging, and never production.
Please check your form action. You need to mention a URL here like example.php.
In case your PHP and HTML script are in the same page, you can keep it blank.
<form id='form' action='' method='post'>
Hope this helps.
You should change
<form id='form' action='#form' method='post'>
to
<form id='form' action='' method='post'>