Ik ben sinds kort met php begonnen.
Tot nu toe lijkt het me allemaal nog heel moeilijk.
1 van de problemen die ik echt niet snap (OOK AL heb ik een handboek gevolgd!) is het volgende:
Notice: Undefined index: firstname in C:\xampp\htdocs\contact.php on line 14
Notice: Undefined index: sent in C:\xampp\htdocs\contact.php on line 16
Notice: Undefined index: sent in C:\xampp\htdocs\contact.php on line 21
Notice: Undefined index: sent in C:\xampp\htdocs\contact.php on line 28
Notice: Undefined index: sent in C:\xampp\htdocs\contact.php on line 35
Notice: Undefined index: sent in C:\xampp\htdocs\contact.php on line 42
Deze error krijg ik in verband met mijn contact formulier (en mijn excuse, ik weet niet hoe ik de lijn-nummers erbij kopieer):
<?php
ini_set("SMTP", "localhost");
ini_set("smtp_port", 25);
ini_set ("sendmail_from", "[email protected]");
function valid_mail ($email) {
return (ereg ('(^[0-9a-zA-Z_\.-]{1,}@([0-9a-zA-Z_\-]{1,}\.)+[0-9a-zA-Z_\-]{2,}$)', $email));
}
function valid_name ($name) {
return (ereg ('^[A-Za-z. -]+$', $name));
}
$_POST["firstname"] = ucfirst($_POST["firstname"]); //No misunderstanding about first letter
if ($_POST["sent"] != "sent" || !valid_name($_POST["firstname"]) || !valid_name($_POST["surname"]) || !valid_email($_POST["email"]) || !$_POST["feedback"]) {
?>
<form action="contact.php" method="post">
<?php
if ($_POST["sent"] && !valid_name($_POST["firstname"])) {
echo "<font color=\"red\">Fill in your firstname correctly.</font><br>";
}
?>
Firstname: <input type="text" name="firstname" id="firstname" value="<?php echo $_POST["firstname"] ?>"><br>
<?php
if ($_POST["sent"] && !valid_name($_POST["surname"])) {
echo "<font color=\"red\">Fill in your surname correctly.</font><br>";
}
?>
Surname: <input type="text" name="surname" id="surname" value="<?php echo $_POST["surname"] ?>"><br>
<?php
if ($_POST["sent"] && !valid_mail($_POST["email"])) {
echo "<font color=\"red\">Fill in your email correctly.</font><br>";
}
?>
E-mail: <input type="text" name="email" id="email" value="<?php echo $_POST["email"] ?>"><br>
<?php
if ($_POST["sent"] && !$_POST["feedback"]) {
echo "<font color=\"red\">Fill in your problem or question, please.</font><br>";
}
?>
Question or Problem: <textarea name="feedback" rows="8" cols="50" id="feedback"><?php echo $_POST["feedback"] ?></textarea>
<input type="submit" value="SENT" name="sent">
</form>
<?php
} else {
$message = "Firstname: ".$_POST["firstname"].$_POST["surname"]."\nQuestion or problem: ".$_POST["feedback"];
mail('[email protected]', "Your reaction from our website", $message);
echo "".$_POST["firstname"].", we will try to give you a feedback as soon as possible.";
}
?>
3.207 views