<?
//Funktion zur Validierung
function validateForm($input,$muss)
{
foreach ($input as $key =>$val)
{
if(in_array($key, $muss))
{
$input[$key][1] = 1;
}
else
{
$input[$key][1] = 0;
}
}
while(list($key,$val)=each($input))
{
switch($key)
{
case "Phone":
if( empty($input[$key][0]) OR (empty($input[$key][0]) AND $input[$key][1] == 1) )
{
$input[$key][2] = 1;
}
else
{
$input[$key][2] = 0;
}
break;
case "Mobile":
if( empty($input[$key][0]) OR (empty($input[$key][0]) AND $input[$key][1] == 1) )
{
$input[$key][2] = 1;
}
else
{
$input[$key][2] = 0;
}
break;
case "Password1":
if( isset($input[$key][0]) AND ($input[$key][0] == $input["Password2"][0]) OR ( isset($input[$key][0]) AND ($input[$key][0] == $input["Password2"][0]) AND $input[$key][1] == 1) )
{
$input[$key][2] = 0;
}
else
{
$input[$key][2] = 1;
}
break;
case "Adress":
if( empty($input[$key][0]) OR (empty($input[$key][0]) AND $input[$key][1] == 1) )
{
$input[$key][2] = 0;
}
else
{
$input[$key][2] = 1;
}
break;
case "Zip":
if( empty($input[$key][0]) OR (empty($input[$key][0]) AND $input[$key][1] == 1) )
{
$input[$key][2] = 1;
}
else
{
$input[$key][2] = 0;
}
break;
} //switch
} //while
return $input;
} //function
if( empty($_POST['controlflag']))
{
// get phone number from the database
//$sql = "SELECT .....";
//$result = mysql_query ($sql);
$input["Mobile"][0] = 12345;
// get mobile number from the database
//$sql = "SELECT .....";
//$result = mysql_query ($sql);
$input["Phone"][0] = 67890;
// get passwd hash from the database
//$sql = "SELECT .....";
//$result = mysql_query($sql);
//$formPhone = @mysql_result($result, 0);
}
if(isset($_POST["formSubmit"]))
{
$required_input=array('Phone','Mobile'); //Felder die gefüllt sein müssen
$input=$_POST["input"]; // aus dem Formular übergebenes Array
$input = validateForm($_POST["input"],$required_input);// return Array mit vier Werten
foreach ($input as $key =>$val)
{
$count += $input[$key][2];
}
if($count == 0)
{
print "Alle Werte OK"; //Eintrag in die Datenbank
}
else
{
if($input["Password1"][2] == 1)
$pwd_error = "<font color=\"#ff0000\"> Please specify two identical passwords.</font>\n";
if($input["Phone"][2] == 1)
$phone_error = "<font color=\"#ff0000\"> Please specify your phone number.</font>\n";
if($input["Mobile"][2] == 1)
$mobile_error = "<font color=\"#ff0000\"> Please specify your cell phone number.</font>\n";
}
}
$content .= "<form method=\"POST\" action=\"form.php\">\n";
$content .="<table border=\"0\" width=\"99%\" cellpadding=\"2\" cellspacing=\"0\" class=\"dtable\">\n";
$content .="<tr class=\"theader\">\n";
$content .="<td colspan=\"2\">Benutzerdaten ändern </td>\n";
$content .="</tr>\n";
$content .="<tr class=\"tbody\">\n";
$content .="<td>Name</td><td align=\"left\">NAME</td>\n";
$content .="</tr>\n";
$content .="<tr class=\"tbody\">\n";
$content .="<td>Vorname</td><td align=\"left\" >VORNAME</td>\n";
$content .="</tr>\n";
$content .="<tr class=\"tbody\">\n";
$content .="<td>Password</td><td align=\"left\" ><input type=\"password\" size=\"50\" maxlength=\"32\" name=\"input[Password1][]\" class=\"text\" /> (Leave blank to stay the same.)";
$content .="</td>\n";
$content .="</tr>\n";
$content .="<tr class=\"tbody\">\n";
$content .="<td>Password (best.)</td><td align=\"left\" ><input type=\"password\" size=\"50\" maxlength=\"32\" name=\"input[Password2][]\" class=\"text\" />".$pwd_error."</td>\n";
$content .="</tr>\n";
$content .="<tr class=\"tbody\">\n";
$content .="<td>E-Mail</td><td align=\"left\" >VORNAME.NACHNAME@PROVIDER.DE</td>\n";
$content .="</tr>\n";
$content .="<tr class=\"tbody\">\n";
$content .="<td>Telefon</td><td align=\"left\" ><input type=\"text\" size=\"50\" maxlength=\"32\" name=\"input[Phone][]\" value=\"".htmlspecialchars($input["Phone"][0])."\" class=\"text\" />".$phone_error."</td>\n";
$content .="</tr>\n";
$content .="<tr class=\"tbody\">\n";
$content .="<td>Mobil</td><td><input type=\"text\" size=\"50\" maxlength=\"32\" name=\"input[Mobile][]\" value=\"".htmlspecialchars($input["Mobile"][0])."\" class=\"text\" />".$mobile_error."</td>\n";
$content .="</tr>\n";
$content .="<tr class=\"tbody\">\n";
$content .="<td align=\"left\"><input type=\"hidden\" name=\"controlflag\" value=\"control_flag\" /></td><td><input type=\"submit\" name=\"formSubmit\" value=\"ändern\" class=\"button\"/></td>\n";
$content .="</tr>\n";
$content .="</table>\n";
$content .="</form>\n";
print $content;
?>