I have a set of two files where my guests shall give personal infomation and make two choices (radiobutton and select) - and after that number 2 file send the result by e-mail to me.
I have got them from a friend (I know almost nothing about php), but unfortunately they do not work right.
Will someone in here help me?
The files can be seen in action at
http://www.fdp.dk/000/
And they should work like that:
The guest MUST give the first four informations.
And he must mark at least one of the two fields.
And he must choose one of the nine radio buttons.
If he does not answer all questions, he shall be notified - and the answers he have already given shall remain in the form.
When everything is ok, the answers shall be sent to me
And the code is beneath.
Thanks
Niels
ntg@mail.dk
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?PHP
$errArray = unserialize($GET['err']);
if (sizeof($errArray) > 0) {
for ($i=0;$i<=sizeof($errArray);$i++) {
print $errArray[$i]."<br>";
}
}
?>
<form action="formhandler.php" method="POST">
<table width="75%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Navn:</td>
<td><input type="text" name="name" value="<?= $POST['name']?>"></td>
</tr>
<tr>
<td>Adresse:</td>
<td><input type="text" name="address" value="<?= $POST['address']?>"></td>
</tr>
<tr>
<td>Postnummer:</td>
<td><input type="text" name="postcode" value="<?= $POST['postcode']?>"></td>
</tr>
<tr>
<td>By:</td>
<td><input type="text" name="city" value="<?= $POST['city']?>"></td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
</tr>
<tr>
<td>Opt 1:</td>
<td>
<?php
if ($POST['checkbox0'] == "checkbox") {
print '<input type="checkbox" name="checkbox0" value="checkbox" checked>';
} else {
print '<input type="checkbox" name="checkbox0" value="checkbox">';
}
if ($POST['checkbox1'] == "checkbox") {
print '<input type="checkbox" name="checkbox1" value="checkbox" checked>';
} else {
print '<input type="checkbox" name="checkbox1" value="checkbox">';
}
?>
</td>
</tr>
<tr>
<td valign="top">Opt 2:</td>
<td>
1:<input type="radio" name="radiobutton" value="1" <? if ($POST['radiobutton'] == 1) {print "checked";} ?>> <br>
2:<input type="radio" name="radiobutton" value="2" <? if ($POST['radiobutton'] == 2) {print "checked";} ?>> <br>
3:<input type="radio" name="radiobutton" value="3" <? if ($POST['radiobutton'] == 3) {print "checked";} ?>> <br>
4:<input type="radio" name="radiobutton" value="4" <? if ($POST['radiobutton'] == 4) {print "checked";} ?>> <br>
5:<input type="radio" name="radiobutton" value="5" <? if ($POST['radiobutton'] == 5) {print "checked";} ?>> <br>
6:<input type="radio" name="radiobutton" value="6" <? if ($POST['radiobutton'] == 6) {print "checked";} ?>> <br>
7:<input type="radio" name="radiobutton" value="7" <? if ($POST['radiobutton'] == 7) {print "checked";} ?>> <br>
8:<input type="radio" name="radiobutton" value="8" <? if ($POST['radiobutton'] == 8) {print "checked";} ?>> <br>
9:<input type="radio" name="radiobutton" value="9" <? if ($POST['radiobutton'] == 9) {print "checked";} ?>> <br>
10:<input type="radio" name="radiobutton" value="10" <? if ($POST['radiobutton'] == 10) {print "checked";} ?>> <br>
11:<input type="radio" name="radiobutton" value="11" <? if ($POST['radiobutton'] == 11) {print "checked";} ?>>
</td>
</tr>
<tr>
<td colspan="2"><div align="right">
<input type="submit" name="Submit" value="Tilmeld">
</div></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if ($POST) {
$errArray = array();
if (empty($POST['name'])) {
array_push($errArray, 'Navn er ikke udfyldt!');
}
if ($POST['address'] == "") {
array_push($errArray, 'Adresse er ikke udfyldt!');
}
if ($POST['postcode'] == "") {
array_push($errArray, 'Postnummer er ikke udfyldt!');
}
if ($POST['city'] == "") {
array_push($errArray, 'By er ikke udfyldt!');
}
if (empty($POST['checkbox0']) && empty($POST['checkbox1'])) {
array_push($errArray, 'En af checkboxene skal være udfyldt!');
}
if (!array_key_exists('radiobutton', $POST)) {
array_push($errArray, 'Der skal markeres en radiobutton!');
}
if (sizeof($errArray) == 0) {
print 'Sender mail...<br />';
$message = "Navn: ".$POST['name']."\r\n";
$message .= "Adresse: ".$POST['address']."\r\n";
$message .= "Postnummer og by: ".$POST['postcode']." ".$POST['city']."\r\n";
$message .= "\r\n";
$message .= "Checkbox0: ".$POST['checkbox0']."\r\n";
$message .= "Checkbox0: ".$POST['checkbox1']."\r\n";
$message .= "Radiobutton: ".$_POST['radiobutton']."\r\n";
//mail('ntg@mail.dk', 'Tilmeldings mail', $message);
if ($POST['checkbox0'] == "checkbox" && !$POST['checkbox1'] == 'checkbox') {
print 'Tekst 1';
} elseif ($POST['checkbox1'] == 'checkbox' && !$POST['checkbox0'] == 'checkbox') {
print 'tekst2';
}
if ($POST['checkbox0'] == 'checkbox' && $POST['checkbox1'] == 'checkbox') {
print 'tekst3';
}
print "<hr noshade size='1'>\n";
} elseif (sizeof($errArray) > 0) {
$err = serialize($errArray);
header("Location: ".$_SERVER['HTTP_REFERER']."?err=".urlencode($err));
}
} /elseif (sizeof($errArray > 0)) {
$err = serialize($errArray);
header("Location: ".$_SERVER['HTTP_REFERER']."?err=".urlencode($err));
}/
?>