tkself

Instructions for use:

Xtensions:

Image: xtension-folder with the extension formmailer

An extension is a piece of code imported from a view-function to handle a specific task. Extensions should be organized in separate files or in separate folders, if an extension is build with more than one file. They are separated from the code of the view-functions. One extension is preinstalled with tk_self: formmailer.

The formmailer can send input from defined forms and form-fields to given e-mail addresses; these definitions are made in the formmailer.ini file, the extension code is in the formmailer.php file. Because this extension has two files it is organized in its own directory.

The formailer.ini file is in the ini-file format, for the "contact"-form four fields are defined:

[contact]
from = sender@example.com
to = recipient@example.com
subject = contact information
items = name, email, message

This will send the content from the form fields

<form action="/sendform/contact/" method="post">
    <input name="name" type="text" size="20" value="the user name" />
    <input name="email" type="text" value="email@example.com"></input>
    <textarea name="message" rows="4" cols="60"></textarea><br />
    <input name="submit" type="submit" value="Submit" />
</form>

to the recipient given by the formmailer.ini file.

A click on the submit-button in the form above will call the URL

http://example.com/sendform/contact/

by a POST-request. This request can be mapped to a function sendmail()

$TK_SELF_URL_PATTERNS = array(
                ...
                "^sendform/contact/?$" => "mail.sendmail",
                ...
                );

that is defined in the file mail in the /views directory:

function sendmail($request_info) {
    require_once(TK_SELF_EXTENSIONS_PATH . 'formmailer/formmailer.php');
    $result = $formmailer->send('contact'$request_info);  // returns boolean
    if ($result) {
        ... do_confirm
    }
    else {
        ... report_failure
    }
}

TK_SELF_EXTENSIONS_PATH is a constant that defines the path to the xtensions-directory and the require_once call for formmailer.php will create an instance of the FormMailer class

$formmailer = new FormMailer();

with the method send() that takes two parameters: the section-name from the formmailer.ini file to use and the $request_info variable. This function will return a boolean: true if the mail has been send successfully or false otherwise.

Contact | Impressum | License