Umlauteproblem mit Kontaktformular

Hilfe zu Modulen und Tags
Post Reply
Lefdi

Umlauteproblem mit Kontaktformular

Post by Lefdi »

Hallo zusammen,

habe ein Problem mit den Umlauten im Kontaktformular und zwar insofern, dass sie nicht richtig dargestellt werden.
Habe hier im Forum bereits was darüber gelesen und daher mein Template und die Metatags auf UTF-8 umgestellt.

Sobald ich aber mein Formular eindeutsche, geht das nicht mehr.

Jetzt hab ich noch gelesen, dass ich im Template wohl was eingeben kann oder muss....nur wo und in welcher Form?

Oder kann ich noch was anderes verstellen....?


Vielen Dank

Lefdi
cyberman

Re: Umlauteproblem mit Kontaktformular

Post by cyberman »

Schau dir mal den Thread an - da ging es schon mal darum

http://forum.cmsmadesimple.org/index.ph ... l#msg26006
matthvis
Forum Members
Forum Members
Posts: 12
Joined: Tue May 09, 2006 11:41 am

Re: Umlauteproblem mit Kontaktformular

Post by matthvis »

Hmmm,
ich habe die Lösung aus dem angegebenen thread gelesen

Code: Select all

if (!empty($_POST['name'])) $name = utf8_decode(cfSanitize($_POST['name']));
nur leider funktioniert das bei mir auch nicht. Der Absender "Rüdiger Süßkind" kommt in meinem Mailprogramm als "RXXdiger SXXXXkind" an. Zwar kein schlechter Name, aber irgendwie... :-\
Ich verwende die function.contact_form.php und die Standard metadaten mit utf-8.

Grüße,
Matthias
cyberman

Re: Umlauteproblem mit Kontaktformular

Post by cyberman »

Hmm, sieht aus, als ob dein Mailproggi Probleme mit de utf-8 Kodierung hat ... hast du da evtl. etwas derartiges eingestellt?
matthvis
Forum Members
Forum Members
Posts: 12
Joined: Tue May 09, 2006 11:41 am

Re: Umlauteproblem mit Kontaktformular

Post by matthvis »

In dem Falle habe ich es mit dem Webmailer von t-online angeschaut, der kann das aber im Normalfall, dass er die Umlaute bei Absendern korrekt darstellt
matthvis
Forum Members
Forum Members
Posts: 12
Joined: Tue May 09, 2006 11:41 am

Re: Umlauteproblem mit Kontaktformular

Post by matthvis »

Ich habe nun die Datei function.contact_form.php so ergänzt, dass der (möglicherweise Umlaute enthaltende) Name und Betreff in den Text der Nachricht mit aufgenommen wird (zusätzliche variable: $antwort, diese wird als Nachrichtentext gesendet und enthält $name, $email, $subject und $message). Die Umlautproblematik bezieht sich ja nur auf die Angabe des Absenders im mailprogramm, nicht auf den Text der Nachricht, da kommen alle Umlaute korrekt an. Hier die modifizierte php Datei:

Code: Select all

<?php

# CMSMS - CMS Made Simple
#
# (c)2004 by Ted Kulp (wishy@users.sf.net)
#
# This project's homepage is: http://cmsmadesimple.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

function smarty_cms_function_contact_form($params, &$smarty) {

    global $gCms;

    if (FALSE == empty($params['captcha']) && $params['captcha'] && isset($gCms->modules['Captcha'])) 
    {
        $captcha =& $gCms->modules['Captcha']['object'];
    }

	if (empty($params['email'])){
		echo '<div class="formError">An email address must be specified in order to use this plugin.</div>';
		return;
	}else{
		$to = $params['email'];
	}
	
	$style = true; // Use default styles
	if (FALSE == empty($params['style']) && $params['style'] === "false" ) $style = false; // Except if "false" given in params
	
	// Default styles
	$inputStyle = ''; // input boxes
	$taStyle = ''; // TextArea boxes
	$formStyle = 'class="formular"'; // form
	$errorsStyle = ''; // Errors box (div)
        $labelStyle = '';
        $buttonStyle = '';
        $fieldsetStyle = '';
        $captchaStyle = 'style="margin-bottom:1em; text-align: center;"';

	$errors=$name=$email=$subject=$message = '';
	if (FALSE == empty($params['subject_get_var']) && FALSE == empty($_GET[$params['subject_get_var']]))
	  {
	    $subject = $_GET[$params['subject_get_var']];
	  }
	if($_SERVER['REQUEST_METHOD']=='POST'){
		if (!empty($_POST['name'])) $name = cfSanitize($_POST['name']);
		if (!empty($_POST['email'])) $email = cfSanitize($_POST['email']);
		if (!empty($_POST['subject'])) $subject = cfSanitize($_POST['subject']);
		if (!empty($_POST['message'])) $message = $_POST['message'];
		
		if (FALSE == empty($params['captcha']) && $params['captcha'] && isset($gCms->modules['Captcha'])) 
		{
		    if (!empty($_POST['captcha_resp'])) { $captcha_resp = $_POST['captcha_resp']; }
		}

		//Mail headers
		$extra = "From: $name <$email>\r\n";
		$charset = isset($gCms->config['default_encoding']) && $gCms->config['default_encoding'] != '' ? $gCms->config['default_encoding'] : 'utf-8';
		$extra .= "Content-Type: text/plain; charset=" . $charset . "\r\n";
		
		if (empty($name)) $errors .= "\t\t<li>" . 'Name' . "</li>\n";
		if (empty($email)) $errors .= "\t\t<li>" . 'E-mail' . "</li>\n";
		elseif (!validEmail($email)) $errors .= "\t\t<li>" . 'Das Feld E-mail mit einer gültigen E-mail Adresse' . "</li>\n";
		if (empty($subject)) $errors .= "\t\t<li>" . 'Betreff' . "</li>\n";
		if (empty($message)) $errors .= "\t\t<li>" . 'Nachricht' . "</li>\n";
		if (FALSE == empty($params['captcha']) && $params['captcha'] && isset($gCms->modules['Captcha']))
		{
		    if (empty($captcha_resp)) $errors .= "\t\t<li>" . 'Please enter the text in the image' . "</li>\n";
		    elseif (! ($captcha->checkCaptcha($captcha_resp))) $errors .= "\t\t<li>" . 'The text from the image was not entered correctly' . "</li>\n";
		}
		
	        $antwort = "Name: ";
		$antwort.= $name;
		$antwort.= "\n";
		$antwort.= "E-mail: ";
		$antwort.= $email;
		$antwort.= "\n";
		$antwort.= "Betreff: ";
		$antwort.= $subject;
		$antwort.= "\n";
		$antwort.= "Nachricht: ";
		$antwort.= $message; 		
	
		
		if (!empty($errors)) {
			echo '<div class="formError" ' . (($style) ? $errorsStyle:'') . '>' . "\n";
			echo '<p>Sie müssen folgende Felder ausfüllen : </p>' . "\n";
			echo "\t<ul>\n";
			echo $errors;
			echo "\t</ul>\n";
			echo "</div>";
		}	
		elseif (@mail($to, $subject, $antwort, $extra)) {
			echo '<div class="formMessage"><p>Vielen Dank für Ihre Nachricht. Ich werde mich so bald wie möglich darum kümmern.</p></div>' . "\n";
			return;
		}
		else {
			echo '<div class="formError" ' . (($style) ? $errorsStyle:'') . '>Ihre Nachricht konnte nicht versendet werden. Versuchen sie es später nocheinmal.</div>' . "\n";
			return;
		}
	}

    if (isset($_SERVER['REQUEST_URI'])) 
    {
	$action = $_SERVER['REQUEST_URI'];
    }
    else
    {
	$action = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';
	if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') 
	{
	    $action .= '?'.$_SERVER['QUERY_STRING'];
	}
    }
?>

	<!-- CONTACT_FORM -->
	<div id="kontaktformular">
	<form action="<?php echo $action ?>" method="post" <?php echo ($style) ? $formStyle:''; ?>>
    <fieldset>             
			<label for="name" <?php echo ($style) ? $labelStyle:''; ?> >Name :</label>
			<input type="text" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" <?php echo ($style) ? $inputStyle:''; ?>/>

			<label for="email" <?php echo ($style) ? $labelStyle:''; ?> >E-mail : </label>
			<input type="text" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" <?php echo ($style) ? $inputStyle:''; ?>/>

			<label for="subject" <?php echo ($style) ? $labelStyle:''; ?> >Betreff : </label>
			<input type="text" id="subject" name="subject" value="<?php echo htmlspecialchars($subject); ?>" <?php echo ($style) ? $inputStyle:''; ?>/>

			<label for="message" <?php echo ($style) ? $labelStyle:''; ?> >Nachricht : </label>
			<textarea id="message" name="message" rows="12" cols="48" <?php echo ($style) ? $taStyle:''; ?>><?php echo $message; ?></textarea>

<?php
if (FALSE == empty($params['captcha']) && $params['captcha'] && isset($gCms->modules['Captcha'])) 
{
?>
			<label for="captcha_resp" <?php echo ($style) ? $labelStyle:''; ?> >Enter the text from the image below : </label>
			<input type="text" id="captcha_resp" name="captcha_resp" value="" <?php echo ($style) ? $inputStyle:''; ?>/>

<?php
    echo "<div $captchaStyle>" . $captcha->getCaptcha() . '</div>';
}
?>

		        <input type="submit" class="button" value="Absenden" <?php echo ($style) ? $buttonStyle: ''; ?> /> 
     </fieldset>           
	</form>
	</div>
	<!-- END of CONTACT_FORM -->

<?php
}

function smarty_cms_help_function_contact_form() {
	?>
	<h3>What does this do?</h3>
	<p>Display's a contact form. This can be used to allow others to send an email message to the address specified.</p>
	<h3>How do I use it?</h3>
	<p>Just insert the tag into your template/page like: <code>{contact_form email="yourname@yourdomain.com"}</code><br>
	<br>
	If you would like to send an email to multiple adresses, seperate each address with a comma.</p>
	<h3>What parameters does it take?</h3>
	<ul>
		<li>email - The email address that the message will be sent to.</li>
		<li><em>(optional)</em>style - true/false, use the predefined styles. Default is true.</li>
		<li><em>(optional)</em>subject_get_var - string, allows you to specify which _GET var to use as the default value for subject.
               <p>Example:</p>
               <pre>{contact_form email="yourname@yourdomain.com" subject_get_var="subject"}</pre>
             <p>Then call the page with the form on it like this: /index.php?page=contact&subject=test+subject</p>
             <p>And the following will appear in the "Subject" box: "test subject"
           </li>
		<li><em>(optional)</em>captcha - true/false, use Captcha response test (Captcha module must be installed). Default is false.</li>
	</ul>
	</p>
	<?php
}

function smarty_cms_about_function_contact_form() {
	?>
	<p>Author: Brett Batie <brett-cms@classicwebdevelopment.com> & Simon van der Linden <ifmy@geekbox.be></p>
	<p>Version: 1.4 (20061010)</p>
	<p>
	Change History:<br/>
        <ul>
        <li>l.2 : various improvements (errors handling, etc.)</li>
        <li>1.3 : added subject_get_var parameter (by elijahlofgren)</li>
        <li>1.4 : added captcha module support (by Dick Ittmann)</li>
        </ul>
	</p>
	<?php
}

function cfsanitize($content){
	return str_replace(array("\r", "\n"), "", trim($content));
}

function validEmail($email) {
	if (!preg_match("/^([\w|\.|\-|_]+)@([\w||\-|_]+)\.([\w|\.|\-|_]+)$/i", $email)) {
		return false;
		exit;
	}
	return true;
}

?>

Geändert sind die Zeilen 83 - 93 sowie Zeile 104 (und die Übersetzungen - @cyberman: wo eigentlich findet man Übersetzungen von Tags? Ich finde nur Übersetzungen von Modulen  ???)
Somit weiß man zumindest, wer einem geschrieben hat-egal wie er oder sie heißt.
cyberman

Re: Umlauteproblem mit Kontaktformular

Post by cyberman »

matthvis wrote: @cyberman: wo eigentlich findet man Übersetzungen von Tags? Ich finde nur Übersetzungen von Modulen  ???)
http://dev.cmsmadesimple.org/frs/?group ... ase_id=746
NaN

Re: Umlauteproblem mit Kontaktformular

Post by NaN »

Sorry, aber ich muss diesen Thread mal wieder herauskramen.

Ich verwende ebenfalls das Script function.contact_form.php.
Die Umlaute werden aber beim Empfänger nicht nur im Namen oder Betreff, sondern auch in der Nachricht immer als kryptische Zeichen dargestellt ( also so: Ü,ü,Ö,ö,Ä,ä,ß).

Ich hab echt keinen Plan wie ich das ändern soll. Hab schon versucht im PHP-Script die Umlaute in der Nachricht mit
$message = str_replace('ü','ü',$message);
zu ändern.
Leider ohne Erfolg. (D.h. es hatte nicht DIE GERINGSTE Auswirkung auf die Variable $message.  ??? )
Das komische ist, wenn ich via Backend mit dem CMSMailer-Modul eine Testnachricht verschicke, werden alle Zeichen korrekt dargestellt (bzw. mit &...; maskiert).


- CMSms 1.2.2 mit allen Standard-Modulen
- Hoster: All-Inkl.
(Fehler tritt derzeit in Verbindung mit dem vom Hoster angebotenen E-Mail Programm Webmail auf.
Andere habe ich noch nicht getestet. Aber das Ergebnis dürfte dort dasselbe sein.)
cyberman

Re: Umlauteproblem mit Kontaktformular

Post by cyberman »

Welche Kodierung verwendet dein Template?
NaN

Re: Umlauteproblem mit Kontaktformular

Post by NaN »

Im Template sowie in allen anderen Einstellungsmöglichkeiten wird die Kodierung UTF-8 bzw. de_DE verwendet.

Allerdings glaube ich, dass ich den Fehler schon gefunden habe.

Es lag wahrscheinlich an den Einstellungen des Mail-Servers.

Hab den Posteingangsserver einfach mal von POP3 auf IMAP gesezt und seit dem scheint alles korrekt zu sein.
susiklein
Forum Members
Forum Members
Posts: 10
Joined: Fri Dec 14, 2007 1:25 pm

Re: Umlauteproblem mit Kontaktformular

Post by susiklein »

habs gefunden.


Die Datenbank ist mit utf-8 codiert und auf der Seite rufe ich es mit htmlentities auf. Hoffe ich habe gehilft
Post Reply

Return to “Module und Tags”