Hey Tanja21,
ich mache das immer so, so hast du auch einen schönen Überblick:
// gebe hier die Felder an, die geprüft werden sollen
$Contents = (object) array(
'name' => ''
,'vorname' => ''
,'strasse' => ''
,'plz' => ''
,'ort' => ''
);
$Classes = new stdClass;
$MayBeBlank = array();
$Errors = 0;
$OnLoad = array();
foreach ($Contents as $Key => $Dump)
$Classes->$Key = 'name_input';
if (true === isset($_REQUEST['name']))
{
$Message = '';
foreach ($Contents as $Key => $Dump)
{
if (false === in_array($Key, $MayBeBlank) and true === empty($_REQUEST[$Key]))
{
$Classes->$Key = 'error';
$Errors++;
}
$Contents->$Key = htmlspecialchars($_REQUEST[$Key]);
$Message .= ucwords($Key) . ': ' . $_REQUEST[$Key] . "\n";
}
if ($Errors == 0)
{
AB HIER KOMMT NUN DAS INSERT IN DIE DATENBANK
So als nächstes brauchst du noch zwei CSS Eigenschaften:
<style type="text/css">
<!--
.name_input { background-color: #efefef;
border: 1px solid #66666;
font-family: helvetica, sans-serif;
font-size: 10px;
font-style: normal;
font-weight: normal;
}
.error { background-color: #993300;
border: 1px solid #66666;
font-family: helvetica, sans-serif;
font-size: 10px;
font-style: normal;
font-weight: normal;
}
-->
</style>
Es ist auch ganz wichtig, dass das .error nach dem name_input kommt, sonst kann er es nicht finden.
So in deinem Formular sieht es dann so aus:
<input name="name" type="text" class="name_input <?php print $Classes->name; ?>" id="name" value="<?php print $Contents->name; ?>" size="70" />
Gruß,
Svenja