I have tried for a very long time now to figure out, why this form is not working. It is not even displaying the error message if you don't type anything.
I hope someone here can point out the problem.
The form is XHTML Strict validated.
<?php
$err = array();
if (isset($_POST['submit'])) {
/* Do the validation */
$uploader_name = $_POST['uploader_name'];
$uploader_mail = $_POST['uploader_mail'];
if (empty($uploader_name)) {
$err[] = "Name is empty.";
}
if (empty($uploader_mail)) {
$err[] = "Mail is empty.";
}
/* If everything is ok, proceed */
if (empty($err)) {
//Do MySQL insert
}
}
echo "<h1>Submit</h1>";
if(!empty($err)) {
echo "<span style='color:red;'>";
foreach ($err as $e) {echo "* $e<br />"; }
echo "</span><br />";
}
echo "
<div>
<form action='' method='post' enctype='text/plain'>
<fieldset>
<legend>Your details</legend>
<label for='uploader_name'>Your name / nickname</label><br />
<input type='text' id='uploader_name' value='$uploader_name' /><br /><br />
<label for='uploader_mail'>Your mail (will not be visible)</label><br />
<input type='text' id='uploader_mail' value='$uploader_mail' /><br /><br />
</fieldset>
<p><input type='submit' id='submit' value='Submit' /></p>
</form>
</div>
";
?>
Fields are sent to server using name
atr, not id
. Add (or replace) ids with names, e.g.:
<input type='submit' name='submit' value='Submit' />
will produce $_POST['submit'] == 'Submit'
UPD: add, not replace. Values are sent via name
, but on the other hand <label />
's are connected with form elements using id
's.
UPD2: And remove enctype
attr from <form>
.