• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Php Kontaktformular checkbox ansteueren

romeosanto

Neues Mitglied
Hallo Zusammen ich habe ein Formular generiert, es funktioniert soweit alles bis auf die checkboxen. Genauergesagt wenn ich das Formular absende geht es an die gewünscht emailadresse (vorübergehend noch meine eigene) und ich bekomme eine zusammenfassung was man alles eingetragen hat (Name, Strasse, Firma.....) ausser bei den drei Checkboxen(unten rot markiert) zeigt es nicht an was ich angeklickt habe. brauche dringend Hilfe!

Dankee;Jump


Hier der Code:




<?php
$your_email ='[email protected]';// <<=== update to your email address

session_start();
$errors = '';
$firma= '';
$vorname= '';
$nachname = '';
$strassenr = '';
$plzort = '';
$telefon = '';
$emailen = '';
$telefonisch = '';
$preislisteunterlagen = '';
$visitor_email = '';
$user_message = '';

if(isset($_POST['submit']))
{
$firma = $_POST['firma'];
$vorname = $_POST['vorname'];
$nachname = $_POST['nachname'];
$strassenr = $_POST['strassennr'];
$plzort = $_POST['plzort'];
$telefon = $_POST['telefon'];
$telefonisch = $_POST['telefonisch'];
$emailen = $_POST['emailen'];
$preislisteunterlagen = $_POST['preislisteunterlagen'];
$visitor_email = $_POST['email'];
$user_message = $_POST['message'];
///------------Do Validations-------------
if(empty($nachname)||empty($visitor_email))
{
$errors .= "\n $nachname und Email sind erforderliche Felder. ";
}
if(IsInjected($visitor_email))
{
$errors .= "\n Bad email value!";
}
if(empty($_SESSION['6_letters_code'] ) ||
strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";
}

if(empty($errors))
{
//send the email
$to = $your_email;
$subject="Formular Swissdisplays.ch";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

$body = "$nachname hat das Kontaktformular von Swissdisplay.ch ausgefüllt\n".
"Firma: $firma\n".
"Vorname: $vorname\n".
"Nachname: $nachname\n".
"Strasse / Nr: $strassenr\n".
"PLZ / Ort: $plzort\n".
"Telefon: $telefon\n".
"kontaktaufnahme: $telefonisch\n".
"kontaktaufnahme: $emailen\n".
"kontaktaufnahme: $preislisteunterlagen\n".
"Email: $visitor_email \n".
"Message: \n ".
"$user_message\n".
"IP: $ip\n";

$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";

mail($to, $subject, $body,$headers);

header('Location: thank-you.html');
}
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact Us</title>
<!-- define some style elements-->
<style>
label,a, body
{
font-family : Arial, Helvetica, sans-serif;
font-size : 12px;
}
.err
{
font-family : Verdana, Helvetica, sans-serif;
font-size : 12px;
color: red;
}
</style>
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
</head>

<body>
<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
<div id='contact_form_errorloc' class='err'></div>
<form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<p>
<label for='firma'>Firma</label><br>
<input type="text" name="firma" value='<?php echo htmlentities($firma) ?>' >
</p>
<p>
<label for='vorname'>Vorname</label><br>
<input type="text" name="vorname" value='<?php echo htmlentities($vorname) ?>' >
</p>
<p>
<label for='nachname'>Nachname</label><br>
<input type="text" name="nachname" value='<?php echo htmlentities($nachname) ?>' >
</p>
<p>
<label for='strassenr'>Strasse / Nr.</label><br>
<input type="text" name="strassenr" value='<?php echo htmlentities($strassenr) ?>' >
</p>
<p>
<label for='plzort'>PLZ / Ort</label><br>
<input type="text" name="plzort" value='<?php echo htmlentities($plzort) ?>' >
</p>
<p>
<label for='telefon'>Telefon</label><br>
<input type="text" name="telefon" value='<?php echo htmlentities($telefon) ?>' >
</p>
<p>
<label for='kontaktaufnahme'>Kontaktaufnahme</label><br>
<input type="checkbox" name="telefonisch" value='<?php echo htmlentities($telefonisch) ?>' > Telefon<br>
<input type="checkbox" name="emailen" value='<?php echo htmlentities($emailen) ?>' > E-Mail<br>
<input type="checkbox" name="preislisteunterlagen" value='<?php echo htmlentities($preislisteunterlagen) ?>' > Preisliste / Unterlagen senden<br>

</p>
<p>
<label for='email'>Email: </label><br>
<input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'>
</p>

<p>
<label for='message'>Message:</label> <br>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
</p>
<p>
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
</p>
<input type="submit" value="Submit" name='submit'>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit JavaScript Form Validation : quick and easy!
// for details
var frmvalidator = new Validator("contact_form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation("firma","req","Please provide your firma");
frmvalidator.addValidation("vorname","req","Please provide your vorname");
frmvalidator.addValidation("nachname","req","Please provide your nachname");
frmvalidator.addValidation("strassenr","req","Please provide your Strasse");
frmvalidator.addValidation("plzort","req","Please provide your plzort");
frmvalidator.addValidation("telefon","req","Please provide your telefon");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
var img = document.images['captchaimg'];
img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
</body>
</html>
 
Wenn Du den input-Feldern vom Typ Checkbox einen Wert geben würdest, könnte man sie auch verarbeiten. Trag z.B. ins value-Attribut fest den Wert 1 ein.

Und verwende bitte Code-Tags wenn Du Quellcode im Forum postest.
 
Zurück
Oben