formularproblemer mht forsvunden tekst!
Hej AlleHåber I kan hjælpe lidt. Jeg har problemer med følgende formular.
Problemer er, at når personen ikke har udfyldt enten tlf, email eller navn, så giver den rigtigt nok en fejlmeddelse, men den sletter det personen har udfyldt i alle felterne. Hvordan får jeg den til at holde op med det?
På forhånd tak!
--------------------
Kode:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>ISOPLASTICON</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function swapImage(imgtag,Image)
{document [imgtag].src = Image}
//-->
</SCRIPT>
<?php
$allowTags = false; // set to true if you want to allow people to post code
function isEmail($email) {
return preg_match("/^(((([^]<>()[\.,;:@\" ]|(\\\[\\x00-\\x7F]))\\.?)+)|(\"((\\\[\\x00-\\x7F])|[^\\x0D\\x0A\"\\\])+\"))@((([[:alpha:]]([[:alnum:]]|-)*[[:alnum:]])\\.?)+|(#[[:digit:]]+)|(\\[([[:digit:]]{1,3}(\\.[[:digit:]]{1,3}){3})]))$/", $email);
}
function stripData($data) {
global $allowTags;
if ($allowTags) {
return stripslashes($data);
}
else {
return strip_tags(stripslashes($data));
}
}
function htmlChars($data) {
return htmlspecialchars(stripData($data), ENT_QUOTES);
}
unset($error);
unset($mailed);
if (isset($_POST['submit'])) {
if (empty($_POST['navn']) || empty($_POST['email']) || empty($_POST['tlf']) ) {
$error = "Du skal mindst udfylde navn, telefonnummer og email";
}
if (!$error) {
if (!isEmail(stripslashes($_POST['email']))) {
$error = "Ikke gyldig email";
}
}
if (!$error) {
$body = "";
$body .= "navn: " . stripData($_POST['navn']) . "\n";
$body .= "email: " . stripData($_POST['email']) . "\n";
$body .= "tlf: " . stripData($_POST['tlf']) . "\n";
$body .= "adresse: " . stripData($_POST['adresse']) . "\n";
$body .= "Post nr: " . stripData($_POST['post']) . "\n";
$body .= "by: " . stripData($_POST['by']) . "\n";
$body .= "interesse: " . stripData($_POST['int']) . "\n";
$body .= "meddelse: " . stripData($_POST['meddelse']) . "\n";
mail("annikahenrik@adslhome.dk", "Besked fra computer4sale", "$body", "From: \"" . stripData($_POST['navn']) . "\" <" . stripslashes($_POST['email']) . ">");
$mailed = "Du har sendt dine informationer, og vi vil behandle dem hurtigst muligt.";
}
}
?>
</head>
<body bgcolor="#F0F0F0">
<center>
<table cellspacing="0" cellpadding="0" width="800" height="500">
<tr>
<td width="800" height="82" background="top.jpg" valign="top" cellspacing="0" cellpadding="0" colspan="2">
</td>
</tr>
<tr valign="top">
<td width="800" height="418" background="bag.jpg" valign="top" cellspacing="0" cellpadding="0" colspan="2">
<table cellspacing="0" cellpadding="0" width="800" height="418">
<tr valign="top">
<td width="174" height="418" background="menu.jpg" valign="middle" cellspacing="0" cellpadding="0">
<?
include "menu.php"
?>
</td>
<td width="626" height="418" valign="top" valign="top" cellspacing="0" cellpadding="0">
<table cellspacing="0" cellpadding="0" width="626" height="418">
<tr valign="top">
<td width="626" height="28" background="topmenu.jpg" valign="middle" cellspacing="0" cellpadding="0">
<?
include "top.php"
?>
</td>
</tr>
<tr valign="top">
<td width="626" height="347" valign="top" cellspacing="0" cellpadding="0">
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="626">
<tr><td valign="top"><p>Navn *:<br><input name="navn" type="text" size="20" maxlength="100" value="">
<p>Email *:<br><input name="email" type="text" size="20" maxlength="100" value=""></p>
<p>Adresse:<br> <input name="adresse" type="text" value="" size="20" maxlength="100"></p>
<p>Post nr: By:<br><input name="post" type="text" value="" size="4" maxlength="100"> <input name="by" type="text" value="" size="20" maxlength="100"></p>
</td><td valign="top"> <p>Tlf. nr *:<br><input name="tlf" type="text" value="" size="20" maxlength="100"></p>
<p>Meddelse:<BR><textarea name="meddelse" size="20" rows="5" maxlength="1000"></textarea></p>
<p><input type="Submit" name="submit" value="Submit"></p></td></tr>
</table>
</form>
<p><B>Status for mail:</B> <? echo "$error"; ?><? echo "$mailed"; ?></p>
</td>
</tr>
<tr valign="top">
<td width="626" height="43" background="bundmenu.jpg" valign="middle" cellspacing="0" cellpadding="0">
<?
include "bund.php"
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</center>
</body>
</html>
