[TYPO3-german] Frage zu error-check bei MailformPlus

Maik maik.vl at web.de
Fri Apr 20 02:38:42 CEST 2007


Hi,

das ist mit der Standardinstallation nicht möglich.
Ich habe aber einen Hook geschrieben, mit dem man
die Daten mit einer eigenen Funktion validieren lassen kann
(der hook wird in der kommenden Mailformplus Version bereits eingebaut sein)

Hier meine modifizierte Version von mailformplus:
http://www.mediavrog.net/typoshare/class.tx_thmailformplus_pi1.phpX
(Einfach die Datei runterladen, das X entfernen und die standard 
class.tx_thmailformplus_pi1.php mit meiner ersetzen)

Bei Misstrauen einfach den Code selbst nachprüfen ^^

Hoffe das hilft dir..

Grüße
Maik

P.S. Hier die Doku zum Hook:

############DOKUMENTATION_begin#####################

*Neu im Typoscript:

*_plugin.tx_thmailformplus_pi1_

errorUserFunc

optional

Sets an user defined function for custom validation.

example:

errorUserFunc = EXT:myext/class.user_myvalidation.php:user_myvalidation->user_validate

See section “Hook for custom validation” for more details.

##############################################

_plugin.tx_thmailformplus_pi1.fieldConf.[name of inputfield]_

.errorCheck

.errorCheck can be one of the following:
*
*- userValidation ... validates the field using the custom validation 
function
how to set the custom validation function see 
plugin.tx_thmailformplus_pi1.errorUserFunc
example for passing parameters to the user function (note: the value of 
the field will be automatically passed as $params['value'])
errorCheck = userValidation
errorCheck{
checkFor=telephonenumber
param2=ger
}

*#############################################

“Hook for custom validation example”
*

This hook gives you the possibility to validate specific fields with 
your own function.

Standard mailformplus functionality are not influenced by this hook.

How to use the hook:

*1.) define a user-function which will do the validation*

create a php file with a class and function which will be called for 
defined fields when the form was submitted:

file:

class.user_myvalidation.php

file content:

class user_myvalidation {

function user_validate(&$params, &$ref){

//var_dump($params);

$input = $params['value'];

switch($params['checkFor']){

case "telephonenumber":

/* first way to do it */
$errorFound = preg_match("/[\+]?([0-9]+[\s]?)+/",$input);
return $errorFound;

/* extended version with custom error messages */
if(strlen($input) < 1){
$error = array("errorFound"=>1,"errorText"=>'Please fill out this field');
}
else{
$errorFound = preg_match("/[\+]?([0-9]+[\s]?)+/",$input);
$error = array("errorFound"=>$errorFound,"errorText"=>'Please enter a 
valid telephone number')
}

return $error;
break;
...
}
}
}

}

The variable $params will hold the following values:

$params['value'] ... the value of the field to be validated

$params[nameOfParameterInTypoScript] ... valueOfParameterInTypoScript
example: if you defined
plugin.tx_thmailformplus_pi1.fieldConf.[name of inputfield].errorCheck = 
userValidation
plugin.tx_thmailformplus_pi1.fieldConf.[name of inputfield].errorCheck{
checkFor=telephonenumber
}

then $params['checkFor'] will be "telephonenumber"

As you can see in the example above, there are two possible return values

1. boolean (0 or 1)
2. array ("errorFound"=>boolean, "errorText"=>"Here you can put your 
custom error message which will override TS Settings");

The $errorFound(boolean) must be false or 0 if no error was found and 
vice versa
Version 2 gives you the ability to display more descriptive error 
messages depending on the input to improve usability (see example)

*2.) activate the hook with TypoScript*

First you have to define the user function that should be used for 
custom valitation:

plugin.tx_thmailformplus_pi1.errorUserFunc = EXT:myext/class.user_myvalidation.php:user_myvalidation->user_validate

Then you'll have to define the fields which should be validated with 
your user function:

plugin.tx_thmailformplus_pi1.fieldConf.[name of inputfield].errorCheck = 
userValidation
plugin.tx_thmailformplus_pi1.fieldConf.[name of inputfield].errorCheck{
checkFor=telephonenumber
param2=ger
}

############DOKUMENTATION_end#####################
*
*


Sebastian Scholz schrieb:
> Hallo
>
> ich hab mich in den letzten Stunden etwas mit MailFormPlus beschäftigt und
> finde es soweit die beste Form Extension für Typo. Allerdings habe ich ein
> Problem bzw Frage zu dem Errorcheck. In meiner momentanen Anwendung reichen
> leider keine normalen Feldbezogenen überprüfungen. Ich habe 2 Felder die
> jeweils ein Datum enthalten und diese Daten dürfen sich nicht überschneiden.
> Im Klartext heisst das ich hab ein "Von" und ein "Bis" Feld. Von "Bis" darf
> nicht vor "Von" liegen.
>
> Ich habe es bisher noch nicht installiert weil ich noch nach anderen Form
> Extensions suche aber ich denke es wird wohl MailFormPlus werden, wenn ich
> dieses Problem gelöst bekomme.
>
> Hoffe mir kann hier jemand weiter helfen.
>
> -Sebastian
> _______________________________________________
> TYPO3-german mailing list
> TYPO3-german at lists.netfielders.de
> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-german
>
>   


More information about the TYPO3-german mailing list