Checkbox bei POST checked


#1
Hallo Freunde, ich habe da ein Kontaktformular von Top-Side.de und brauche für dieses Formular eine Checkbox mit dem Namen "erstinformation". Diese Checkbox soll angeklickt werden und ist ein Pflichtfeld. Ich habe jetzt viele Sachen aus dem Netz ausprobiert und bin jetzt nur soweit gekommen das wenn ich es nicht anklicke, die Fehlermeldung erscheint. Das Problem ist aber, wenn man es anklickt, die Fehlermeldung weg ist, aber das Häckchen nicht nicht gesetzt wird. Ich bitte euch werft mal einen Blick auf das Script. Ich mach da was FALSCH.

Code:
<?php
/*
* tsFormmailer
*
* @version 1.0.1
* @copyright (c) Top-Side.de
* @license CC BY-NC-SA 4.0
* @link http://www.top-side.de
*
*/

session_start();
include("fm_files/config.php");



$border = "border: ".$settings['border_width']."px ".$settings['border_style']." ".$settings['border_color'];
$style = "body { font-family: ".$settings['font_family']."; font-size: ".$settings['font_size']."pt; background: ".$settings['color_background']." }\n";
$style .= "table { border-collapse: collapse; spacing: 0 }\n";
$style .= "td, .tbl { color: ".$settings['font_color']."; padding: 5px; background: ".$settings['color_background_center']."; ".$border." }\n";
$style .= ".left { background: ".$settings['color_column_left']."; font-weight: bold; vertical-align: top }\n";
$style .= ".right { background: ".$settings['color_column_right']." }\n";
$style .= "a:link, a:active, a:visited { color: ".$settings['link_color']."; text-decoration: ".$settings['link_style']." }\n";
$style .= "a:hover { color: ".$settings['link_color_hover']."; text-decoration: ".$settings['link_style_hover']." }\n";
$style .= "input, textarea, select { color: ".$settings['font_color']."; background-color: ".$settings['color_background_center']."; ".$border." }\n";
$style .= "img { border: none }\n";
$style .= ".uppercase { text-transform: uppercase; }\n";

function replaceChars($text, $html = true)
{
    $char = array("ä", "Ä", "ö", "Ö", "ü", "Ü", "ß", " ");
    if($html)
        $char_replace = array("&auml;", "&Auml;", "&ouml;", "&Ouml;", "&uuml;", "&Uuml;", "&szlig;", " ");
    else
        $char_replace = array("ae", "ae", "oe", "oe", "ue", "ue", "ss", "_");
    return utf8_encode(str_replace($char, $char_replace, utf8_decode(trim($text))));
}

echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"de\">\n";
echo "<head>\n";
echo "<title>".$settings['title']."</title>\n";
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n";
echo "<style type=\"text/css\">\n".$style."</style>\n";
echo "</head>\n";
echo "<body>\n";

$mail_send = false;
$error = "";
if(isset($_POST['send']))
{
    if(!preg_match("/^[a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])+@[a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])+\.[a-zA-Z]{2,4}$/", $_POST['sender']))
        $error .= "&bull; ung&uuml;ltige E-Mail Adresse angeben<br />\n";
    if(!preg_match("/^[a-zA-Z0-9äÄöÖüÜß\-\/\(\)\.\:, ]{3,50}$/", $_POST['subject']))
        $error .= "&bull; ung&uuml;ltigen Betreff angeben<br />\n";
    if($settings['attachment'] && $_FILES['attachment']['name'] != "")
    {
        $filename = $_FILES['attachment']['name'];
        if($_FILES['attachment']['size'] > $settings['attachment_size'] * 1024)
            $error .= "&bull; Anhang zu gro&szlig; (max. ".$settings['attachment_size']." KB)<br />\n";
        $path_parts = pathinfo($filename);
        $ext_file = strtolower($path_parts['extension']);
        $ext_valid = explode(",", str_replace(" ", "",  $settings['attachment_extensions']));
        if(!in_array($ext_file, $ext_valid))
            $error .= "&bull; Ung&uuml;ltige Dateiendung im Anhang (nur ".$settings['attachment_extensions'].")<br />\n";
    }
    if(empty($_POST['text']))
        $error .= "&bull; keinen Text geschrieben<br />\n";
       
    if(empty($_POST['erstinformation']))
        $error .= "&bull; Erstinformation nicht gelesen<br />\n";
       
    if($settings['captcha'] != 0)
    {
        if(($settings['captcha'] == 1 || $settings['captcha'] == 2) && trim(strtoupper($_POST['captcha'])) != $_SESSION['captcha'])
            $error .= "&bull; falschen Sicherheitscode eingegeben<br />\n";
        elseif($settings['captcha'] == 3)
        {
            $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$settings['recaptcha_privatekey']."&response=".$_POST['g-recaptcha-response']);
            $response_json = json_decode($response);
            if(!$response_json->success)
                $error .= "&bull; falschen Sicherheitscode eingegeben<br />\n";
        }
       
       
       
    }
    if($error == "")
    {
        $mail_header = "MIME-Version: 1.0\r\n";
        $mail_header .= "From: ".$_POST['sender']."\r\n";
        $mail_header .= "X-Mailer: PHP ".phpversion()."\r\n";
       
        if($settings['html_mail'])
        {
            $mail_text = "<html>\n<head>\n<title>".$_POST['subject']."</title>\n</head>\n<body>\n";
            if(trim($settings['user_fields']) != "")
            {
                $arr_user_fields = explode(",", $settings['user_fields']);
                $mail_text .= "<table>\n";
                for($i = 0; $i < count($arr_user_fields); $i++)
                {
                    if(!empty($_POST[replaceChars($arr_user_fields[$i], false)]))
                        $mail_text .= "<tr><td><strong>".replaceChars($arr_user_fields[$i]).":</strong></td><td>".$_POST[replaceChars($arr_user_fields[$i], false)]."</td></tr>\n";
                }
                $mail_text .= "</table>\n";
            }
            $mail_text .= "<p>\n".replaceChars(nl2br($_POST['text']))."\n</p>\n";
            $mail_text .= "</body>\n</html>";
        }
        else
        {
            $mail_text = "";
            if(trim($settings['user_fields']) != "")
            {
                $arr_user_fields = explode(",", $settings['user_fields']);
                for($i = 0; $i < count($arr_user_fields); $i++)
                {
                    if(!empty($_POST[replaceChars($arr_user_fields[$i], false)]))
                        $mail_text .= trim($arr_user_fields[$i]).":\n".$_POST[replaceChars($arr_user_fields[$i], false)]."\n\n";
                }
            }
            $mail_text .= $_POST['text'];
        }
       
        if($settings['attachment'] && $_FILES['attachment']['name'] != "")
        {
            $boundary = md5(time());
            $mail_header .= "Content-Type: multipart/mixed; boundary=".$boundary."\r\n\r\n";
           
            $mail_body = "This is a multi-part message in MIME format\r\n";
            $mail_body .= "--".$boundary."\r\n";
            if($settings['html_mail'])
                $mail_body .= "Content-type: text/html; charset=utf-8\r\n";
            else
                $mail_body .= "Content-type: text/plain; charset=utf-8\r\n";
            $mail_body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
            $mail_body .= $mail_text;
            $mail_body .= "\r\n--".$boundary."\r\n";
            $mail_body .= "Content-Type: application/octet-stream; name=\"".$_FILES['attachment']['name']."\"\r\n";
            $mail_body .= "Content-Transfer-Encoding: base64\r\n";
            $mail_body .= "Content-Disposition: attachment; filename=\"".$_FILES['attachment']['name']."\"\r\n\r\n";
            $mail_body .= chunk_split(base64_encode(file_get_contents($_FILES['attachment']['tmp_name'])))."\r\n";
        }
        else
        {
            if($settings['html_mail'])
                $mail_header .= "Content-type: text/html; charset=utf-8\r\n";
            else
                $mail_header .= "Content-type: text/plain; charset=utf-8\r\n";
           
            $mail_body = $mail_text;
        }
        mail($settings['mail_address'], $_POST['subject'], $mail_body, $mail_header);
        $mail_send = true;
    }
}

if($mail_send)
{
    echo "<table style=\"margin: 0px auto\">\n";
    echo "<tr><td colspan=\"2\">\n";
    echo "<span style=\"color: #008b00; font-weight: bold\">E-Mail wurde erfolgreich gesendet.</span>\n";
    echo "</td></tr>\n";
    echo "</table>\n";
}
else
{
    echo "<form action=\"mail.php\" method=\"post\"";
    if($settings['attachment'])
        echo "enctype=\"multipart/form-data\"";
    echo ">\n";
    echo "<table style=\"margin: 0px auto\">\n";
    echo "<tr>\n";
    echo "<td align=\"center\" colspan=\"2\"><strong>".$settings['title']."</strong></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td class=\"left\">E-Mail Adresse</td>\n";
    echo "<td class=\"right\"><input type=\"text\" size=\"30\" name=\"sender\"".((isset($_POST['sender'])?" value=\"".$_POST['sender']."\"":""))." /></td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td class=\"left\">Betreff</td>\n";
    echo "<td class=\"right\"><input type=\"text\" size=\"30\" name=\"subject\"".((isset($_POST['subject'])?" value=\"".$_POST['subject']."\"":""))." /></td>\n";
    echo "</tr>\n";
    if(trim($settings['user_fields']) != "")
    {
        $arr_user_fields = explode(",", $settings['user_fields']);
        for($i = 0; $i < count($arr_user_fields); $i++)
        {
            echo "<tr>\n";
            echo "<td class=\"left\">".replaceChars($arr_user_fields[$i])."</td>\n";
            $field_name = replaceChars($arr_user_fields[$i], false);
            echo "<td class=\"right\"><input type=\"text\" size=\"30\" name=\"".$field_name."\"".((isset($_POST[$field_name])?" value=\"".$_POST[$field_name]."\"":""))." /></td>\n";
            echo "</tr>\n";
        }
    }
    if($settings['attachment'])
    {
        echo "<tr>\n";
        echo "<td class=\"left\">Anhang</td>\n";
        echo "<td class=\"right\"><input type=\"file\" size=\"30\" name=\"attachment\" /><br />(max. ".$settings['attachment_size']." KB; ".$settings['attachment_extensions'].")</td>\n";
        echo "</tr>\n";
    }
    echo "<tr>\n";
    echo "<td class=\"left\">Text</td>\n";
    echo "<td class=\"right\"><textarea name=\"text\" rows=\"10\" cols=\"50\">".((isset($_POST['text'])?$_POST['text']:""))."</textarea></td>\n";
    echo "</tr>\n";
   
   

    echo "<td class=\"left\">Erstinformation</td>\n";
    $active = isset($_POST['erstinformation']) && $_POST['erstinformation']  ? "1" : "0";
    echo "<td class=\"right\"><input type=\"checkbox\" size=\"30\" name=\"erstinformation\"".((isset($_POST[$erstinformation])?" value=\"".$active=""."\"":""))." /></td>\n";
    echo "</tr>\n";
   
   
    if($settings['captcha'] != 0)
    {
        echo "<tr>\n";
        echo "<td class=\"left\">Sicherheitscode</td>\n";
        echo "<td class=\"right\">\n";
        switch($settings['captcha'])
        {
            case 1:
            {
                echo "<script type=\"text/javascript\">\nfunction randomcode(dirname) {\nx = new Date().getTime();\ndocument.images.captcha.src = dirname + '/fm_files/captcha/captcha.php?x=' + x;\n}\n</script>\n";
                echo "<img src=\"fm_files/captcha/captcha.php?".session_name()."=".session_id()."\" id=\"captcha\" onclick=\"javascript: randomcode('".dirname($_SERVER['PHP_SELF'])."');\" alt=\"Sicherheitscode\" /><br />\n";
                echo "<span style=\"font-size: ".($settings['font_size'] * 0.75)."pt\">(Grafik klicken f&uuml;r neuen Sicherheitscode)</span><br /><br />\n";
                echo "<input type=\"text\" name=\"captcha\" class=\"uppercase\" size=\"25\" maxlength=\"5\" />\n";
                echo "<input type=\"hidden\" name=\"".session_name()."\" value=\"".session_id()."\" />\n";
                break;
            }
            case 2:
            {
                echo "<img src=\"fm_files/captcha/calccaptcha.php?".session_name()."=".session_id()."\" alt=\"Sicherheitscode\" style=\"vertical-align: middle\" />&nbsp;=&nbsp;\n";
                echo "<input type=\"text\" name=\"captcha\" class=\"uppercase\" size=\"1\" maxlength=\"2\" />\n";
                echo "<input type=\"hidden\" name=\"".session_name()."\" value=\"".session_id()."\" />\n";
                break;
            }
            case 3:
            {
                echo "<script src=\"https://www.google.com/recaptcha/api.js\" async defer></script>\n";
                echo "<div class=\"g-recaptcha\" data-sitekey=\"".$settings['recaptcha_publickey']."\"></div>\n";
                break;
            }
        }
        echo "</td>\n";
        echo "</tr>\n";
    }

    echo "<tr>\n";
    echo "<td align=\"center\" colspan=\"2\"><input type=\"submit\" name=\"send\" value=\"Senden\" /></td>\n";
    echo "</tr>\n";
    if(isset($_POST['send']) && $error != "")
    {
        echo "<tr><td colspan=\"2\">\n";
        echo "<span style=\"color: #ff0000; font-weight: bold\">\n".$error."</span>\n";
        echo "</td></tr>\n";
    }
    echo "</table>\n";
    echo "</form>\n";
}

echo "<div class=\"tbl\" style=\"width: 250px; margin: 0px auto; text-align: center; margin-top: 20px\">\n";
echo "tsFormmailer &copy; <a href=\"http://www.top-side.de\">top-side.de</a>\n";
echo "</div>\n";

echo "</body>\n";
echo "</html>\n";
?>