From 6f125a20df39454f1f785075998d0c0751055ba5 Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Sat, 3 Dec 2011 12:47:55 +0000 Subject: [PATCH] Pruefung ob indiv. Feld gesetzt wurde, funktioniert. Feld laesst sich jetzt auch als optional definieren. --- form-email/config.php | 4 ++-- form-email/mailer.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/form-email/config.php b/form-email/config.php index 7818660..fc01978 100644 --- a/form-email/config.php +++ b/form-email/config.php @@ -48,8 +48,8 @@ $text_max = 0; $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']['optional'] = 1; +$user_fields['beruf']['regex'] = '/^[A-Za-z]+$/'; $user_fields['beruf']['check'] = 'check_beruf'; $user_fields['beruf']['tpl_var'] = 'BERUF'; diff --git a/form-email/mailer.php b/form-email/mailer.php index b32f095..52e3110 100644 --- a/form-email/mailer.php +++ b/form-email/mailer.php @@ -96,6 +96,14 @@ $prepared_user_fields = array(); while(list($user_field,$user_field_data) = each($user_fields)) { $user_field_content = formdata($user_field); + + if((!$user_field_data['optional']) && (!$user_field_content)) { + show_user_error($user_field_data['errors']['not_set']); + } + elseif($user_field_data['optional'] && (!$user_field_content)) { + $prepared_user_fields[$user_field_data['tpl_var']] = ''; + continue; + } 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) === false) { -- 2.34.1