Fertigen Kontakt-Formular erweitern

arraybreak

Erfahrenes Mitglied
Abend,

ich habe hier einen guten Kontakt-Formular gefunden den ich gern nutzen würde. Das Problem dabei ist das er mir ein wenig zu klein ist, ich möchte dem Absender mehr Angabe-Flächen ermöglichen, wie z.B. Anschrift, Geburtsdatum, Telefon etc.

Wenn ich die Flächen im Formular einfüge nutzt es mir nicht viel, da wahrscheinlich der Script die Dateien nicht zum mir schickt, wie kann ich dann die zusätzlichen Angaben zu mir schicken lassen.

Für den großen Code entschuldige ich mich, aber ich denke dass es besser wäre den ganzen Code zu posten:

PHP:
<?php

// User settings
$to = "muster@mail.de";
$subject = "Kontakt";

// Include extra form fields and/or submitter data?
// false = do not include
$extra = array(
	"form_subject"	=> true,
	"form_cc"		=> false,
	"ip"			=> false,
	"user_agent"	=> false
);

// Process
$action = isset($_POST["action"]) ? $_POST["action"] : "";
if (empty($action)) {
	// Send back the contact form HTML
	$output = "<div style='display:none'>
	<div class='contact-top'></div>
	<div class='contact-content'>
		<h1 class='contact-title'>Send us a message:</h1>
		<div class='contact-loading' style='display:none'></div>
		<div class='contact-message' style='display:none'></div>
		<form action='#' style='display:none'>
			<label for='contact-name'>*Name:</label>
			<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' />
			<label for='contact-email'>*Email:</label>
			<input type='text' id='contact-email' class='contact-input' name='email' tabindex='1002' />";

	if ($extra["form_subject"]) {
		$output .= "
			<label for='contact-subject'>Subject:</label>
			<input type='text' id='contact-subject' class='contact-input' name='subject' value='' tabindex='1003' />";
	}

	$output .= "
			<label for='contact-message'>*Message:</label>
			<textarea id='contact-message' class='contact-input' name='message' cols='40' rows='4' tabindex='1004'></textarea>
			<br/>";

	if ($extra["form_cc"]) {
		$output .= "
			<label>&nbsp;</label>
			<input type='checkbox' id='contact-cc' name='cc' value='1' tabindex='1005' /> <span class='contact-cc'>Send me a copy</span>
			<br/>";
	}

	$output .= "
			<label>&nbsp;</label>
			<button type='submit' class='contact-send contact-button' tabindex='1006'>Send</button>
			<button type='submit' class='contact-cancel contact-button simplemodal-close' tabindex='1007'>Cancel</button>
			<br/>
			<input type='hidden' name='token' value='" . smcf_token($to) . "'/>
		</form>
	</div>
</div>";

	echo $output;
}
else if ($action == "send") {
	// Send the email
	$name = isset($_POST["name"]) ? $_POST["name"] : "";
	$email = isset($_POST["email"]) ? $_POST["email"] : "";
	$subject = isset($_POST["subject"]) ? $_POST["subject"] : $subject;
	$message = isset($_POST["message"]) ? $_POST["message"] : "";
	$cc = isset($_POST["cc"]) ? $_POST["cc"] : "";
	$token = isset($_POST["token"]) ? $_POST["token"] : "";

	// make sure the token matches
	if ($token === smcf_token($to)) {
		smcf_send($name, $email, $subject, $message, $cc);
		echo "Your message was successfully sent.";
	}
	else {
		echo "Unfortunately, your message could not be verified.";
	}
}

function smcf_token($s) {
	return md5("smcf-" . $s . date("WY"));
}

// Validate and send email
function smcf_send($name, $email, $subject, $message, $cc) {
	global $to, $extra;

	// Filter and validate fields
	$name = smcf_filter($name);
	$subject = smcf_filter($subject);
	$email = smcf_filter($email);
	if (!smcf_validate_email($email)) {
		$subject .= " - invalid email";
		$message .= "\n\nBad email: $email";
		$email = $to;
		$cc = 0; // do not CC "sender"
	}

	// Add additional info to the message
	if ($extra["ip"]) {
		$message .= "\n\nIP: " . $_SERVER["REMOTE_ADDR"];
	}
	if ($extra["user_agent"]) {
		$message .= "\n\nUSER AGENT: " . $_SERVER["HTTP_USER_AGENT"];
	}

	// Set and wordwrap message body
	$body = "From: $name\n\n";
	$body .= "Message: $message";
	$body = wordwrap($body, 70);

	// Build header
	$headers = "From: $email\n";
	if ($cc == 1) {
		$headers .= "Cc: $email\n";
	}
	$headers .= "X-Mailer: PHP/SimpleModalContactForm";

	// UTF-8
	if (function_exists('mb_encode_mimeheader')) {
		$subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n");
	}
	else {
		// you need to enable mb_encode_mimeheader or risk 
		// getting emails that are not UTF-8 encoded
	}
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/plain; charset=utf-8\n";
	$headers .= "Content-Transfer-Encoding: quoted-printable\n";

	// Send email
	@mail($to, $subject, $body, $headers) or 
		die("Unfortunately, a server issue prevented delivery of your message.");
}

// Remove any un-safe values to prevent email injection
function smcf_filter($value) {
	$pattern = array("/\n/","/\r/","/content-type:/i","/to:/i", "/from:/i", "/cc:/i");
	$value = preg_replace($pattern, "", $value);
	return $value;
}

// Validate email address format in case client-side validation "fails"
function smcf_validate_email($email) {
	$at = strrpos($email, "@");

	// Make sure the at (@) sybmol exists and  
	// it is not the first or last character
	if ($at && ($at < 1 || ($at + 1) == strlen($email)))
		return false;

	// Make sure there aren't multiple periods together
	if (preg_match("/(\.{2,})/", $email))
		return false;

	// Break up the local and domain portions
	$local = substr($email, 0, $at);
	$domain = substr($email, $at + 1);


	// Check lengths
	$locLen = strlen($local);
	$domLen = strlen($domain);
	if ($locLen < 1 || $locLen > 64 || $domLen < 4 || $domLen > 255)
		return false;

	// Make sure local and domain don't start with or end with a period
	if (preg_match("/(^\.|\.$)/", $local) || preg_match("/(^\.|\.$)/", $domain))
		return false;

	// Check for quoted-string addresses
	// Since almost anything is allowed in a quoted-string address,
	// we're just going to let them go through
	if (!preg_match('/^"(.+)"$/', $local)) {
		// It's a dot-string address...check for valid characters
		if (!preg_match('/^[-a-zA-Z0-9!#$%*\/?|^{}`~&\'+=_\.]*$/', $local))
			return false;
	}

	// Make sure domain contains only valid characters and at least one period
	if (!preg_match("/^[-a-zA-Z0-9\.]*$/", $domain) || !strpos($domain, "."))
		return false;	

	return true;
}

exit;

?>

Für Antworten danke ich im voraus.

Gruß Alex
 
Hallo arraybreak,

ich würde dir echt gern helfen, aber ich hab den Eindruck, es ist fast einfacher, dir das komplette Skript neu zu schreiben, als dieses anzupassen.

Gib mir mal ein paar Infos zu deinem Kenntnisstand.

Bist du in der Lage, irgendetwas selbst zu machen (z. B. die Formularfelder hinzuzufügen). Wenn ja, mach das mal und poste das Skript wieder.

Mir den dann benötigten PHP-Zeilen kann ich dir dann gern helfen. Zumindest solange du nicht noch hundert Sachen validieren möchtest.
 
Hi Anna Bolika,

also meine Kenntnisse reichen nur zum ändern des Scripts aber nicht zum selber schreiben von irgend welchen Funktionen :(

Die Formularfelder kann ich natürlich selber anbringen, bloß dachte ich, das ich nicht weit komme wenn ich den Rest nicht kann :)

Vielen Dank voraus dass du dich einverstanden erklärst mir zu helfen :)
Werde dann in ca. 30 min den Code posten, hoffe du kannst mir helfen

Gruß Alex
 
Für den Fall, dass ich dann nicht mehr online sein sollte, hier schon mal was zum ausprobieren:

Du änderst diese Zeile:

PHP:
$message = isset($_POST["message"]) ? $_POST["message"] : "";

und tauschst sie gegen dies hier aus. Ist ne quick-&-dirty-Lösung, müsste aber gehen

PHP:
$message = @$_POST['message'] . "\r\n\r\n";

$message .= 'Telefon: ' . @$_POST['telefon'] . "\r\n\r\n";
$message .= 'Telefax: ' . @$_POST['telefax'] . "\r\n\r\n";
$message .= 'Straße: ' . @$_POST['strasse'] . "\r\n\r\n";

// usw.

Die Bezeichnungen innerhalb des $_POST-Arrays entsprechend dem name-Attribut innerhalb des <input>-Feldes in HTML.

Wenns nicht klappt, meldest du dich einfach wieder.
 
So hab jetzt die fehlenden Flächen eingefügt und nach deinem Beispiel diese auch zu PHP zugefügt, es funktioniert! :D Danke dir!

So nun habe ich noch paar Fragen, kannst du vielleicht kurz gucken ob es passt?
Bei Fläche "Adresse" habe ich drei Angabeflächen, eins wird aber nicht zentriert zu anderen angezeigt.
Wie kann ich kleine untertitel (unter den jeweiligen Flächen) schreiben, damit man weiß was man da eintragen muss.

PHP:
<?php

// User settings
$to = "alex@localhost";
$subject = "Bewerbung";

// Include extra form fields and/or submitter data?
// false = do not include
$extra = array(
	"form_subject"	=> true,
	"form_cc"		=> true,
	"ip"			=> false,
	"user_agent"	=> false
);

// Process
$action = isset($_POST["action"]) ? $_POST["action"] : "";
if (empty($action)) {
	// Send back the contact form HTML
	$output = "<div style='display:none'>
	<div class='contact-top'><h1 class='contact-title'>Jetzt Partner werden</h1></div>
	<div class='contact-content'>
		
		<div class='contact-loading' style='display:none'></div>
		<div class='contact-message' style='display:none'></div>
		<form action='#' style='display:none'>	
			
			<label for='contact-name'>*Name, Vorname:</label>
			<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' />
			
			<label for='contact-adresse'>*Adresse:</label>
			<input type='text' id='contact-strasse' class='contact-input' name='strasse' tabindex='1001' />
			<input type='text' id='contact-plz' class='contact-input' name='plz' tabindex='1001' />
			<input type='text' id='contact-ort' class='contact-input' name='ort' tabindex='1001' />		
			
			<label for='contact-gb'>*Geburtsdatum:</label>
			<input type='text' id='contact-gb' class='contact-input' name='gb' tabindex='1002' />
			
			<label for='contact-ausbildung'>*Ausbildung bzw. schulische Ausbildung:</label>
			<input type='text' id='contact-ausbildung' class='contact-input' name='ausbildung' tabindex='1002' />
			
			<label for='contact-bferfahrung'>*bisherige Berufserfahrung:</label>
			<input type='text' id='contact-bf-erfahrung' class='contact-input' name='bf-erfahrung' tabindex='1002' />
			
			<label for='contact-aktaetigkeit'>*aktuelle berufliche Tätigkeit:</label>
			<input type='text' id='contact-aktaetigkeit' class='contact-input' name='aktaetigkeit' tabindex='1002' />
			
			<label for='contact-telefon'>*Telefon:</label>
			<input type='text' id='contact-telefon' class='contact-input' name='telefon' tabindex='1002' />
	
			<label for='contact-email'>*Email:</label>
			<input type='text' id='contact-email' class='contact-input' name='email' tabindex='1002' />";

	if ($extra["form_subject"]) {
		$output .= "
			<label for='contact-subject'>Betreff:</label>
			<input type='text' id='contact-subject' class='contact-input' name='subject' value='' tabindex='1003' />";
	}

	$output .= "
			<label for='contact-message'>*Ihre Nachricht:</label>
			<textarea id='contact-message' class='contact-input' name='message' cols='40' rows='4' tabindex='1004'></textarea>
			<br/>";

	if ($extra["form_cc"]) {
		$output .= "
			<label>&nbsp;</label>
			<input type='checkbox' id='contact-cc' name='cc' value='1' tabindex='1005' /> <span class='contact-cc'>Eine Kopie an mich</span>
			<br/>";
	}

	$output .= "
			<label>&nbsp;</label>
			<button type='submit' class='contact-send contact-button' tabindex='1006'>Absenden</button>
			<button type='submit' class='contact-cancel contact-button simplemodal-close' tabindex='1007'>Abbrechen</button>
			<br/>
			<input type='hidden' name='token' value='" . smcf_token($to) . "'/>
		</form>
	</div>
</div>";

	echo $output;
}
else if ($action == "send") {
	// Send the email
	$name = isset($_POST["name"]) ? $_POST["name"] : "";
	$email = isset($_POST["email"]) ? $_POST["email"] : "";
	$subject = isset($_POST["subject"]) ? $_POST["subject"] : $subject;
	
	$message = @$_POST['message'] . "\r\n\r\n";

	$message .= 'Strasse: ' . @$_POST['strasse'] . "\r\n\r\n";
	$message .= 'PLZ: ' . @$_POST['plz'] . "\r\n\r\n";
	$message .= 'Ort: ' . @$_POST['ort'] . "\r\n\r\n";
	$message .= 'Geburtsdatum: ' . @$_POST['gb'] . "\r\n\r\n";
	$message .= 'Ausbildung: ' . @$_POST['ausbildung'] . "\r\n\r\n";
	$message .= 'Berufserfahrung: ' . @$_POST['bf-erfahrung'] . "\r\n\r\n";
	$message .= 'Aktuelle-Taetigkeit: ' . @$_POST['aktaetigkeit'] . "\r\n\r\n";
	
	$message .= 'Telefon: ' . @$_POST['telefon'] . "\r\n\r\n";

	
	$cc = isset($_POST["cc"]) ? $_POST["cc"] : "";
	$token = isset($_POST["token"]) ? $_POST["token"] : "";

	// make sure the token matches
	if ($token === smcf_token($to)) {
		smcf_send($name, $email, $subject, $message, $cc);
		echo "Ihre Nachricht wurde erfolgreich uebermittelt.";
	}
	else {
		echo "Leider konnte Ihre Nachricht nicht verifiziert werden.";
	}
}

function smcf_token($s) {
	return md5("smcf-" . $s . date("WY"));
}

// Validate and send email
function smcf_send($name, $email, $subject, $message, $cc) {
	global $to, $extra;

	// Filter and validate fields
	$name = smcf_filter($name);
	$subject = smcf_filter($subject);
	$email = smcf_filter($email);
	if (!smcf_validate_email($email)) {
		$subject .= " - invalid email";
		$message .= "\n\nBad email: $email";
		$email = $to;
		$cc = 0; // do not CC "sender"
	}

	// Add additional info to the message
	if ($extra["ip"]) {
		$message .= "\n\nIP: " . $_SERVER["REMOTE_ADDR"];
	}
	if ($extra["user_agent"]) {
		$message .= "\n\nUSER AGENT: " . $_SERVER["HTTP_USER_AGENT"];
	}

	// Set and wordwrap message body
	$body = "From: $name\n\n";
	$body .= "Message: $message";
	$body = wordwrap($body, 70);

	// Build header
	$headers = "From: $email\n";
	if ($cc == 1) {
		$headers .= "Cc: $email\n";
	}
	$headers .= "X-Mailer: PHP/SimpleModalContactForm";

	// UTF-8
	if (function_exists('mb_encode_mimeheader')) {
		$subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n");
	}
	else {
		// you need to enable mb_encode_mimeheader or risk 
		// getting emails that are not UTF-8 encoded
	}
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/plain; charset=utf-8\n";
	$headers .= "Content-Transfer-Encoding: quoted-printable\n";

	// Send email
	@mail($to, $subject, $body, $headers) or 
		die("Unfortunately, a server issue prevented delivery of your message.");
}

// Remove any un-safe values to prevent email injection
function smcf_filter($value) {
	$pattern = array("/\n/","/\r/","/content-type:/i","/to:/i", "/from:/i", "/cc:/i");
	$value = preg_replace($pattern, "", $value);
	return $value;
}

// Validate email address format in case client-side validation "fails"
function smcf_validate_email($email) {
	$at = strrpos($email, "@");

	// Make sure the at (@) sybmol exists and  
	// it is not the first or last character
	if ($at && ($at < 1 || ($at + 1) == strlen($email)))
		return false;

	// Make sure there aren't multiple periods together
	if (preg_match("/(\.{2,})/", $email))
		return false;

	// Break up the local and domain portions
	$local = substr($email, 0, $at);
	$domain = substr($email, $at + 1);


	// Check lengths
	$locLen = strlen($local);
	$domLen = strlen($domain);
	if ($locLen < 1 || $locLen > 64 || $domLen < 4 || $domLen > 255)
		return false;

	// Make sure local and domain don't start with or end with a period
	if (preg_match("/(^\.|\.$)/", $local) || preg_match("/(^\.|\.$)/", $domain))
		return false;

	// Check for quoted-string addresses
	// Since almost anything is allowed in a quoted-string address,
	// we're just going to let them go through
	if (!preg_match('/^"(.+)"$/', $local)) {
		// It's a dot-string address...check for valid characters
		if (!preg_match('/^[-a-zA-Z0-9!#$%*\/?|^{}`~&\'+=_\.]*$/', $local))
			return false;
	}

	// Make sure domain contains only valid characters and at least one period
	if (!preg_match("/^[-a-zA-Z0-9\.]*$/", $domain) || !strpos($domain, "."))
		return false;	

	return true;
}

exit;

?>

ps: Was hat es mit dem "tabindex" auf sich?
 
Zuletzt bearbeitet:
Ich kann leider dein Programm nicht ganz durchsehen und auch nicht testen.

Das mit dem zentrieren verstehe ich nicht ganz, aber ich sehe, dass du keine <label> vor allein Eingabefeldern hast.

tabindex ist ein Attribut, mit dem du steuern kannst in welcher Reihenfolge die Felder mit der TAB-Taste angesprungen werden. Meisten ist dieses Attribut überflüssig, weil du ja die Reihenfolge willst, in de die Felder auf dem Bildschirm stehen.

Wenn ich Untertitel schreiben müsste, würde ich <span>-Tags voransetzen mit dem gleichen Style wie die <label>, allerdings nur mit &nbsp; als Inhalt. Dahinter würde ich in <small> die Erklärung setzen.

Kennst du dich mit CSS etwas aus?
 
Hi, habe es gerade ausprobiert mit <span> aber leider will das nicht stehen wie ich das möchte :(

Alle 3 Untertitel stehen im einem Feld und nicht unter 3 verschiedenen

HTML:
<label for='contact-strasse'>*Adresse:</label>
<input type='text' id='contact-strasse' class='contact-input' name='strasse' />
<span for='contact-strasse'>&nbsp;<small>Strasse und Hausnummer</small></span>
			
<label for='contact-stadt'>&nbsp;</label>
<input type='text' id='contact-stadt' class='contact-input' name='stadt' />
<span for='contact-stadt'>&nbsp;<small>Stadt</small></span>
			
<label for='contact-plz'>&nbsp;</label>
<input type='text' id='contact-plz' class='contact-input' name='plz' />
<span for='contact-plz'>&nbsp;<small>Postleitzahl</small></span>


irgend was mache ich falsch :D
 
Zurück