This page contains deprecated components, that are not contained in release 1.11. Thus, this page now is under development until this message is removed. If you have, any question, please create a new thread in our support forum.
Please refer to the German language copy&paste wiki tutorial to see how the contact form can be included into your web page.
/config/tools/form/taglib/{CONTEXT}/{ENVIRONMENT}_formconfig.ini/config/tools/form/taglib/sites/demosite/DEFAULT_formconfig.iniPlease fill the field in e-mail address!Please provide a valid e-mail address!<form:validate
button="send"
field="email"
type="EMail"
msginputreq="Contact.EMail.InputRequired"
msginputwrg="Contact.EMail.InputWrong"
/>[de]
Contact.EMail.InputRequired = "Bitte geben Sie eine E-Mail-Adresse sein!"
Contact.EMail.InputWrong = "Bitte geben Sie eine gültige E-Mail-Adresse sein!"
[en]
Contact.EMail.InputRequired = "Please fill the field sender name!"
Contact.EMail.InputWrong = "Please provide a valid email address!"/config/modules/kontakt4/{CONTEXT}/{ENVIRONMENT}_language.ini;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Deutsche Texte ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[de]
; Header
header.title = "Kontakt"
; Hinweise zum Formular
formhint.text = "Wenn Sie mit mir in Kontakt treten möchten, dann benutzen Sie einfach dieses Formular. Geben Sie Ihre Nachricht ein und schon kann es los gehen. Ich werden mich dann umgehend mit Ihnen in Verbindung setzten. Bitte füllen Sie das Formular vollständig aus!"
; Formular
form.person = "Person / Gruppe: "
form.name = "Ihr Name:"
form.email = "Ihre E-Mail-Adresse:"
form.subject = "Ihr Betreff:"
form.comment = "Ihre Nachricht:"
form.button = "Senden"
form.captcha = "Bestätigungscode:"
; confirmation text
message.text = "Vielen Danke für Ihre Anfrage. Ich werde mich umgehend mit Ihnen in Verbindung setzen!"
; validation messages
form.name.error = "Bitte füllen Sie das Feld Absender-Name!"
form.email.error = "Bitte geben Sie eine gültige E-Mail-Adresse sein!"
form.subject.error = "Bitte füllen Sie das Feld Betreff!"
form.text.error = "Bitte füllen Sie das Feld Text!"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Englisch texts ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[en]
; header
header.title = "Contact"
; hints on the form
formhint.text = "If you want to contact me, please use the form provided below. Then I will immediately get in contact with you. Please fill all required fields!"
; form labels
form.person = "Person / group: "
form.name = "Your name:"
form.email = "Your email address:"
form.subject = "Your subject:"
form.comment = "Your message:"
form.button = "Send"
form.captcha = "Security code:"
; confirmation text
message.text = "Many thanks for your message. We will get in contact with you immediately!"
; validation messages
form.name.error = "Please provide a sender name!"
form.email.error = "Please provide a valid email address!"
form.subject.error = "Please fill the subject field!"
form.text.error = "The message may not be empty!"// Load language dependent configuration
$Config = $this->getConfiguration('modules::kontakt4','language');
// Get a reference on the desired form control
$Button = &$Form->getFormElementByName('KontaktSenden');
// Set the value attribute of the control using the <em>$this->language</em> member
$Button->setAttribute('value',$Config->getSection($this->language)->getValue('form.button'));/modules/
kontakt4/
biz/
data/
pres/
documentcontroller/
templates/<font style="..."><html:getstring namespace="modules::kontakt4" config="language" entry="header.title" /></font>
<br />
<br />
<core:importdesign namespace="modules::kontakt4::pres::templates" template="[pagepart=formular]" /><@controller namespace="modules::kontakt4::pres::documentcontroller" class="contact_form_controller" @>
<core:addtaglib namespace="tools::form::taglib" class="HtmlFormTag" prefix="html" name="form" />
<p>
<html:getstring namespace="modules::kontakt4" config="language" entry="formhint.text" />
</p>
<div class="contact-form">
<html:form name="contact" method="post">
<div>
<form:error id="toperror">
<div class="error-container">
<ul>
</form:error>
<form:listener control="AbsenderName" id="sender-error">
<li><listener:placeholder name="content" /></li>
</form:listener>
<form:listener control="AbsenderAdresse" id="addr-error">
<li><listener:placeholder name="content" /></li>
</form:listener>
<form:listener control="Betreff" id="subject-error">
<li><listener:placeholder name="content" /></li>
</form:listener>
<form:listener control="Text" id="text-error">
<li><listener:placeholder name="content" /></li>
</form:listener>
<form:listener control="captcha" id="captcha-error">
<li><listener:placeholder name="content" /></li>
</form:listener>
<form:error id="bottomerror">
</ul>
</div>
</form:error>
<form:addvalidator
class="TextLengthValidator"
button="sendFormContact"
control="AbsenderName|Betreff|Text"
/>
<form:addvalidator
class="EMailValidator"
button="sendFormContact"
control="AbsenderAdresse"
/>
<form:addfilter
class="EMailFilter"
button="sendFormContact"
control="AbsenderAdresse"
/>
<label for="contact-form-recipient">
<form:getstring namespace="modules::kontakt4" config="language" entry="form.person" />
</label>
<form:select id="contact-form-recipient" name="Empfaenger" />
<label for="contact-form-sendername">
<form:getstring namespace="modules::kontakt4" config="language" entry="form.name" />
</label>
<form:text id="contact-form-sendername" name="AbsenderName" />
<label for="contact-form-recipient-email">
<form:getstring namespace="modules::kontakt4" config="language" entry="form.email" />
</label>
<form:text id="contact-form-recipient-email" name="AbsenderAdresse" />
<label for="contact-form-subject">
<form:getstring namespace="modules::kontakt4" config="language" entry="form.subject" />
</label>
<form:text id="contact-form-subject" name="Betreff" />
<label for="contact-form-textarea">
<form:getstring namespace="modules::kontakt4" config="language" entry="form.comment" />
</label>
<form:area id="contact-form-textarea" name="Text" cols="50" rows="6"/>
<div class="fullsizebox captchabox">
<label for="contact-form-captcha">
<form:getstring namespace="modules::kontakt4" config="language" entry="form.captcha" />
</label>
<form:addtaglib namespace="modules::captcha::pres::taglib" class="SimpleCaptchaTag" prefix="form" name="captcha" />
<form:captcha
name="captcha-control"
clearonerror="true"
text_id="contact-form-captcha"
disable_inline="true"
/>
<form:addvalidator
namespace="modules::captcha::pres::validator"
class="CaptchaValidator"
control="captcha-control"
button="sendFormContact"
/>
</div>
<div class="fullsizebox buttonbox">
<form:button name="sendFormContact" class="button"/>
</div>
</div>
</html:form>
</div><br />
<html:getstring namespace="modules::kontakt4" config="language.ini" entry="message.text" />
<br />
<br />import('tools::link', 'LinkGenerator');
import('modules::kontakt4::biz', 'ContactFormData');
class contact_form_controller extends BaseDocumentController {
public function transformContent() {
$form = & $this->getForm('contact');
// generate a generic action url, to be included in various pages
$action = LinkGenerator::generateUrl(Url::fromCurrent());
$form->setAction($action);
// fill recipient list
/* @var $recipients SelectBoxTag */
$recipients = & $form->getFormElementByName('Empfaenger');
/* @var $cM ContactManager */
$cM = & $this->getServiceObject('modules::kontakt4::biz', 'ContactManager');
/* @var $recipientList ContactFormRecipient[] */
$recipientList = $cM->loadRecipients();
for ($i = 0; $i < count($recipientList); $i++) {
$recipients->addOption($recipientList[$i]->getName(), $recipientList[$i]->getId());
}
if ($form->isSent() && $form->isValid()) {
$formData = new ContactFormData();
/* @var $recipient SelectBoxTag */
$recipient = & $form->getFormElementByName('Empfaenger');
$option = & $recipient->getSelectedOption();
$recipientId = $option->getAttribute('value');
$formData->setRecipientId($recipientId);
$name = & $form->getFormElementByName('AbsenderName');
$formData->setSenderName($name->getAttribute('value'));
$email = & $form->getFormElementByName('AbsenderAdresse');
$formData->setSenderEmail($email->getAttribute('value'));
$subject = & $form->getFormElementByName('Betreff');
$formData->setSubject($subject->getAttribute('value'));
$text = & $form->getFormElementByName('Text');
$formData->setMessage($text->getContent());
/* @var $cM ContactManager */
$cM = & $this->getServiceObject('modules::kontakt4::biz', 'ContactManager');
$cM->sendContactForm($formData);
} else {
// label the button
$config = $this->getConfiguration('modules::kontakt4', 'language');
$value = $config->getSection($this->language)->getValue('form.button');
$button = & $form->getFormElementByName('sendFormContact');
$button->setAttribute('value', $value);
// fill listeners with the language dependent values
$senderError = & $form->getFormElementByID('sender-error');
$senderError->setPlaceHolder('content', $config->getSection($this->language)->getValue('form.name.error'));
$addrError = & $form->getFormElementByID('addr-error');
$addrError->setPlaceHolder('content', $config->getSection($this->language)->getValue('form.email.error'));
$subjectError = & $form->getFormElementByID('subject-error');
$subjectError->setPlaceHolder('content', $config->getSection($this->language)->getValue('form.subject.error'));
$textError = & $form->getFormElementByID('text-error');
$textError->setPlaceHolder('content', $config->getSection($this->language)->getValue('form.text.error'));
$captchaError = & $form->getFormElementByID('captcha-error');
$captchaError->setPlaceHolder('content', $config->getSection($this->language)->getValue('form.captcha.error'));
$form->transformOnPlace();
}
}
}Taking a closer look to the source code, you can see, that the controller class uses two more components: the RequestHandler and the ContactManager. The first class is a class integrated in the framework, that registers request variables in a locally used array and fills this offsets with default values if not present in the request. Details on this class can be seen on the RequestHandler page. The second component is the business layer class of the contact form. This class provides interfaces to load recipients or to submit the form.
The method transformContent() takes over the generation of the view. For this reason a reference on the form object is fetched to check, wheather the form is sent and filled correctly. If not, the form is displayed in the current view. Is the user input considered ok, a form data domain object is created and filled. After that the business component is created by use of the getServiceObject() method. The function sendContactForm() called with the domain object ContactFormData as an argument then sends the data of the form via mail. The submission and the redirection to the thank-you-message is completely done by the business layer.
import('modules::kontakt4::biz', 'ContactFormData');
import('modules::kontakt4::biz', 'ContactFormRecipient');
import('tools::link', 'LinkGenerator');
import('tools::http', 'HeaderManager');
class ContactManager extends APFObject {
public function sendContactForm(ContactFormData $formData) {
$cM = &$this->getServiceObject('modules::kontakt4::data', 'ContactMapper');
// set up the mail sender
$MAIL = &$this->getAndInitServiceObject('tools::mail', 'mailSender', 'ContactForm');
$recipient = $cM->loadRecipientPerId($formData->getRecipientId());
$MAIL->setRecipient($recipient->getEmailAddress(), $recipient->getName());
$Text = 'Sehr geehrter Empfänger, sehr geehrte Empfängerin,';
$Text .= "\n\n";
$Text .= $formData->getSenderName() . ' (E-Mail: ' . $formData->getSenderEmail() . ') hat Ihnen folgende Nachricht über das Kontaktformular zukommen lassen:';
$Text .= "\n\n\n";
$Text .= $formData->getMessage();
$MAIL->setContent($Text);
$MAIL->setSubject($formData->getSubject());
// send mail to notify the recipient
$MAIL->sendMail();
$MAIL->clearRecipients();
$MAIL->clearCCRecipients();
$MAIL->clearContent();
$MAIL->setRecipient($formData->getSenderEmail(), $formData->getSenderName());
$Text = 'Sehr geehrter Empfänger, sehr geehrte Empfängerin,';
$Text .= "\n\n";
$Text .= 'Ihre Anfrage wurde an die Kontaktperson "' . $recipient->getName() . '" weitergeleitet. Wir setzen uns baldmöglich mit Ihnen in Verbindung!';
$Text .= "\n\n";
$Text .= 'Hier nochmals Ihr Anfragetext:';
$Text .= "\n";
$Text .= $formData->getMessage();
$MAIL->setContent($Text);
$MAIL->setSubject($formData->getSubject());
// send mail to notify the sender
$MAIL->sendMail();
// redirect to the thanks page to avoid F5 bugs!
$link = LinkGenerator::generateUrl(Url::fromCurrent()->mergeQuery(array('contactview' => 'thanks')));
$urlRewriting = Registry::retrieve('apf::core', 'URLRewriting');
if ($urlRewriting != true) {
$link = str_replace('&', '&', $link);
}
HeaderManager::forward($link);
}
public function loadRecipients() {
$cM = & $this->getServiceObject('modules::kontakt4::data', 'ContactMapper');
return $cM->loadRecipients();
}
}import('modules::kontakt4::biz','ContactFormData');
import('modules::kontakt4::biz','ContactFormRecipient');
class ContactMapper extends APFObject {
public function loadRecipients(){
// read config
$Config = $this->getConfiguration('modules::kontakt4','empfaenger.ini');
// initialize return array
$Recipients = array();
// parse config and generate recipients
foreach($Config->getSectionNames() as $name){
$Count = count($Recipients);
$Recipients[$Count] = new ContactFormRecipient();
// id
preg_match("/Kontakt ([0-9]+)/i",$name,$Matches);
$Recipients[$Count]->set('oID',$Matches[1]);
// name
$Recipients[$Count]->set('Name',$Config->getSection($name)->getValue('EmpfaengerName'));
// email
$Recipients[$Count]->set('Adresse',$Config->getSection($name)->getValue('EmpfaengerAdresse'));
}
// return recipient list
return $Recipients;
}
public function loadRecipientPerId($Id){
$Rec = $this->loadRecipients();
if(!is_array($Rec)){
return array();
}
else{
for($i = 0; $i < count($Rec); $i++){
if($Rec[$i]->get('oID') == $Id){
return $Rec[$i];
}
}
}
}
}[Kontakt ([0-9]+)]
EmpfaengerName = "([A-Za-z0-9,.-_ ]+)"
EmpfaengerAdresse = "([A-Za-z0-9.-_@]+)"JetBRAINS supports the development of the APF with PHPStorm licenses and we feel confidential that PHPStorm strongly influences the APF's quality. Use PHPStorm!
Proud to useIntelligent PHP IDE for coding, testing and debugging with pleasure