From 2ed757f514862fe67ac1c77af781b6bee3aeb388 Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Sat, 3 Dec 2011 12:37:36 +0000 Subject: [PATCH] Regex und Check-Funktion fuer indiv. Formularfelder funktionieren jetzt richtig --- form-email/config.php | 15 +++++++++++++-- form-email/mailer.php | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/form-email/config.php b/form-email/config.php index 13e68b8..7818660 100644 --- a/form-email/config.php +++ b/form-email/config.php @@ -50,13 +50,24 @@ $user_fields['beruf']['min'] = 5; $user_fields['beruf']['max'] = 50; $user_fields['beruf']['optional'] = 0; $user_fields['beruf']['regex'] = '/^[A-Za-z]$/'; -$user_fields['beruf']['check'] = ''; +$user_fields['beruf']['check'] = 'check_beruf'; $user_fields['beruf']['tpl_var'] = 'BERUF'; $user_fields['beruf']['errors']['too_short'] = 'Der Beruf muss mind. 5 Zeichen lang sein!'; $user_fields['beruf']['errors']['too_long'] = 'Der Beruf darf höchstens 50 Zeichen lang sein!'; $user_fields['beruf']['errors']['not_set'] = 'Sie haben keinen Beruf eingegeben!'; -$user_fields['beruf']['errors']['no_match'] = 'Der Beruf darf nur aus Buchstaben bestehen!'; +$user_fields['beruf']['errors']['match_fail'] = 'Der Beruf darf nur aus Buchstaben bestehen!'; +$user_fields['beruf']['errors']['check_fail'] = 'Der Beruf sollte keine äöü haben!'; + +# Beispiel-Check-Funktion + +function check_beruf($content) { + if(strpos($content,'ä') !== false) return false; + if(strpos($content,'ö') !== false) return false; + if(strpos($content,'ü') !== false) return false; + + return true; +} # Sicherheit diff --git a/form-email/mailer.php b/form-email/mailer.php index c85d206..b32f095 100644 --- a/form-email/mailer.php +++ b/form-email/mailer.php @@ -98,13 +98,13 @@ while(list($user_field,$user_field_data) = each($user_fields)) { $user_field_content = formdata($user_field); if(isset($user_field_data['check']) && $user_field_data['check'] != '') { - if(function_exists($user_field_data['check']) && call_user_func($user_field_data['check'],$user_field_content)) { + if(function_exists($user_field_data['check']) && call_user_func($user_field_data['check'],$user_field_content) === false) { show_user_error($user_field_data['errors']['check_fail']); } } if(isset($user_field_data['regex']) && $user_field_data['regex'] != '') { - if(preg_match($user_field_data['regex'],$user_field_content)) { + if(!preg_match($user_field_data['regex'],$user_field_content)) { show_user_error($user_field_data['errors']['match_fail']); } } -- 2.34.1