Typo3 Extension Development – Bar54 http://www.bar54.de Software Engineering, Web Technologies, eCommerce and some more Sat, 28 Sep 2013 04:51:11 +0000 en-US hourly 1 https://wordpress.org/?v=5.9.4 Powermail 1.6 – Custom JavaScript Validation http://www.bar54.de/2012/05/powermail-1-6-custom-javascript-validation/ http://www.bar54.de/2012/05/powermail-1-6-custom-javascript-validation/#respond Tue, 15 May 2012 07:25:49 +0000 http://www.bar54.de/blog/?p=232 Powermail is one of the most mature and recomendable Typo3 extensions for online forms. It is easy to use, extend and maintain. I used it in many different projects with different requirements such as spam protection, visitor registration, questionairs, and many more.

For the 1.6 generation of the extension, the JavaScript part was completly migrated to the jquery framework. In conjunction with this migration, the javascript-based client-side input validation was migrated to the jquery tools validator: http://www.jquerytools.org/documentation/validator/index.html
With this validator, it is still possible to customize the form validation. However, this is not included in the powermail documentation yet and I hope this post will help you to understand how this can be done. If not, just let me know!

The JavaScript Template File
So first, powermail uses a template file containing the frontend javascript validation. This file is imported and parsed by the extension to replace placeholders such as labels and others.
The original file can be found in the extension resources at

typo3conf/ext/powermail/templates/tmpl_frontend.js

You can customize this file, upload it and configure it in your website template either in the constant editor or directly in the constants using:

plugin.powermail.template.frontendJsTemplatePath = path/to/your/templatefile.js

Accessing the powermail Validator Object
In the template file, the powermail validator is created and accessible via the javascript object

powermail_validator.data('validator')

This object provides your access to the validator in your custom code. For example to reset the validation

powermail_validator.data('validator').reset()

Or to trigger the validation

powermail_validator.data('validator').checkValidity()

Register new Validators
Validators can be registered directly for the jquery tools validator in the default way: http://www.jquerytools.org/documentation/validator/index.html#custom

This can be done using the method

$.tools.validator.fn(...);

This method requires 3 parameters:
1. The css selector to register the validator for (e.g. ‘select’ for all select tags or ‘.powermail_uid67’ to reference the powermail field with the id UID67.
2. Error messages for the validator (either a string for the default language or an associative array for multiple languages)
3. The validator function itself. The function get’s two parameters: the field element that is validated and the value to be validated. This function can have different return values: { true: the value is valid; false: The value is invalid; string: The value is invalid and this is the error message to display; object: value is invalid and the object contains localized error messages}

As an example this is the default validation for the select elements:

	// select validation
	$.tools.validator.fn('select', '',
		function(el, value) {
			(el.attr('multiple')) {
				return value != null ? true: '###VALIDATOR_LABEL_ONE_REQUIRED###';
			} else {
				return value.length > 0 ? true : '';
			}
		}
	);
]]>
http://www.bar54.de/2012/05/powermail-1-6-custom-javascript-validation/feed/ 0
Email Subject in Typo3 Extension with spam protection http://www.bar54.de/2011/12/email-subject-in-typo3-extension-with-spam-protection/ http://www.bar54.de/2011/12/email-subject-in-typo3-extension-with-spam-protection/#respond Fri, 30 Dec 2011 07:22:38 +0000 http://www.bar54.de/blog/?p=157 Developing a typo3 extension which is generating output, presenting a link for an email address is no matter using the function getTypoLink(). But as soon, as you try to add a predefined subject with space characters to the mail and you have turned on the build in spam protection feature, this can lead into some trouble.

Your subject may be stripped at the first whitespace. Then you can try to urlencode() or rawurlencode() the subject before you add the parameter to the email address. But even this would fail, because there will be + or 0 characters be placed in the subject instead of the whitespaces.

Typo3 provides a more low level method to get the required infos for the email link generated and taking care for the spam protection configuration. This method is called getMailTo(mailAdrress, LinkText) and it returns an array with the mailto link at index 0 and the link text at index 1. This is the first step to the solution. But it still has one limitation. When you add a ‘?subject=my subject with spaces’ to the email link, the spam protection configuration will be annuled for the link text. so you might end up with the unprotected email address again.

The final solution will be to call getMailTo() twice. Once to generate the email link including the subject and another time to protect the link text. Afterwards you can pick up the best of the two arrays you have generated. The code snippet below shows an example of the solutions application.


$mailInfosLink =
$this->cObj->getMailTo(
$emailAddress.'?subject=Email subject with multiple words',
$emailAddress);
$mailInfosText = $this->cObj->getMailTo($emailAddress,$emailAddress);
$email = ''.$mailInfosText[1].'';

]]>
http://www.bar54.de/2011/12/email-subject-in-typo3-extension-with-spam-protection/feed/ 0
Typo3: Output of the Last Executed SQL Query in an Extension http://www.bar54.de/2011/08/typo3-output-of-the-last-executed-sql-query-in-an-extension/ http://www.bar54.de/2011/08/typo3-output-of-the-last-executed-sql-query-in-an-extension/#respond Sat, 13 Aug 2011 11:17:26 +0000 http://www.bar54.de/blog/?p=97 While developing a Typo3 extension you might send queries to your database table to read or write some data.
Typo3 supports different comfortable functions to ease up the query definition. Due to this, there is no point in your code where you have the full sql statement available to debug this. So to find out what a query looks like that was finally submitted to the database, you could either check the database itself or use a Typo3 internal feature to retrieve the last submitted query.

Typo3 provides the class t3lib_DB to phrase your SQL query. The used instance of this class could also be configured to store the last database query executed to later access and check it.
The following code example shows how to use this feature in your extension code:


// activate query protocol
$GLOBALS['TYPO3_DB']->store_lastBuiltQuery = TRUE;

// execute database query
$resultSet = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(...);

// printout the captured query
// Note: you should use log capabilitites instead of print_r() in production!
print_r($GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);

]]>
http://www.bar54.de/2011/08/typo3-output-of-the-last-executed-sql-query-in-an-extension/feed/ 0
Typo3: Email Link Subject in Extension with Spam Protection http://www.bar54.de/2011/08/typo3-email-subject-extension-with-spam-protection/ http://www.bar54.de/2011/08/typo3-email-subject-extension-with-spam-protection/#respond Thu, 04 Aug 2011 07:01:29 +0000 http://www.bar54.de/blog/?p=87 Developing a typo3 extension which is generating output, presenting a link for an email address is no matter using the function getTypoLink(). But as soon, as you try to add a predefined subject with space characters to the mail and you have turned on the build in spam protection feature, this can lead into some trouble.

Your subject may be stripped at the first whitespace. Then you can try to urlencode() or rawurlencode() the subject before you add the parameter to the email address. But even this would fail, because there will be + or 0 characters be placed in the subject instead of the whitespaces.

Typo3 provides a more low level method to get the required infos for the email link generated and taking care for the spam protection configuration. This method is called getMailTo(mailAdrress, LinkText) and it returns an array with the mailto link at index 0 and the link text at index 1. This is the first step to the solution. But it still has one limitation. When you add a ‘?subject=my subject with spaces’ to the email link, the spam protection configuration will be annuled for the link text. so you might end up with the unprotected email address again.

The final solution will be to call getMailTo() twice. Once to generate the email link including the subject and another time to protect the link text. Afterwards you can pick up the best of the two arrays you have generated. The code snippet below shows an example of the solutions application.


$mailInfosLink =
$this->cObj->getMailTo(
$emailAddress.'?subject=Email subject with multiple words',
$emailAddress);
$mailInfosText = $this->cObj->getMailTo($emailAddress,$emailAddress);
$email = '
'.$mailInfosText[1].'';

]]> http://www.bar54.de/2011/08/typo3-email-subject-extension-with-spam-protection/feed/ 0