summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-31 23:55:24 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-31 23:55:24 +0200
commitf5e7a053fe74f4b00d7a68c6ea06472c400bdba6 (patch)
tree631d68021a1288a7b814701a5ea9855f6ea00d60
parent9abe372a0aa14187f1a3e098d2f2b7c99f746c09 (diff)
downloadwebadmin-f5e7a053fe74f4b00d7a68c6ea06472c400bdba6.tar.gz
Improve handling of optional form fields
-rw-r--r--lib/api/kolab_api_service_group.php47
-rw-r--r--lib/api/kolab_api_service_user.php38
2 files changed, 49 insertions, 36 deletions
diff --git a/lib/api/kolab_api_service_group.php b/lib/api/kolab_api_service_group.php
index e7fef8a..700ff25 100644
--- a/lib/api/kolab_api_service_group.php
+++ b/lib/api/kolab_api_service_group.php
@@ -62,7 +62,10 @@ class kolab_api_service_group extends kolab_api_service
if (isset($gta['form_fields'])) {
foreach ($gta['form_fields'] as $key => $value) {
error_log("form field $key");
- if (!isset($postdata[$key]) || $postdata[$key] === '') {
+ if (
+ (!isset($postdata[$key]) || empty($postdata[$key]) &&
+ !(array_key_exists('optional', $value) || $value['optional'])
+ ) {
throw new Exception("Missing input value for $key", 345);
}
else {
@@ -73,10 +76,14 @@ class kolab_api_service_group extends kolab_api_service
if (isset($gta['auto_form_fields'])) {
foreach ($gta['auto_form_fields'] as $key => $value) {
- if (!isset($postdata[$key])) {
- throw new Exception("Key not set: " . $key, 12356);
- }
- else {
+ if (empty($postdata[$key])) {
+ if (!array_key_exists('optional', $value) || $value['optional']) {
+ $postdata['attributes'] = array($key);
+ $res = $form_service->generate($getdata, $postdata);
+ $postdata[$key] = $res[$key];
+ $group_attributes[$key] = $postdata[$key];
+ }
+ } else {
$group_attributes[$key] = $postdata[$key];
}
}
@@ -84,12 +91,7 @@ class kolab_api_service_group extends kolab_api_service
if (isset($gta['fields'])) {
foreach ($gta['fields'] as $key => $value) {
- if (!isset($postdata[$key]) || empty($postdata[$key])) {
- $group_attributes[$key] = $gta['fields'][$key];
- }
- else {
- $group_attributes[$key] = $postdata[$key];
- }
+ $group_attributes[$key] = $gta['fields'][$key];
}
}
@@ -162,7 +164,10 @@ class kolab_api_service_group extends kolab_api_service
if (isset($gta['form_fields'])) {
foreach ($gta['form_fields'] as $key => $value) {
- if (!isset($postdata[$key]) || empty($postdata[$key])) {
+ if (
+ (!isset($postdata[$key]) || empty($postdata[$key])) &&
+ !(array_key_exists('optional', $value) && $value['optional'])
+ ) {
throw new Exception("Missing input value for $key", 345);
}
else {
@@ -174,21 +179,21 @@ class kolab_api_service_group extends kolab_api_service
if (isset($gta['auto_form_fields'])) {
foreach ($gta['auto_form_fields'] as $key => $value) {
if (empty($postdata[$key])) {
- $postdata['attributes'] = array($key);
- $res = $form_service->generate($getdata, $postdata);
- $postdata[$key] = $res[$key];
+ if (!array_key_exists('optional', $value) || $value['optional']) {
+ $postdata['attributes'] = array($key);
+ $res = $form_service->generate($getdata, $postdata);
+ $postdata[$key] = $res[$key];
+ $group_attributes[$key] = $postdata[$key];
+ }
+ } else {
+ $group_attributes[$key] = $postdata[$key];
}
- $group_attributes[$key] = $postdata[$key];
}
}
if (isset($gta['fields'])) {
foreach ($gta['fields'] as $key => $value) {
- if (!isset($postdata[$key]) || empty($postdata[$key])) {
- $group_attributes[$key] = $gta['fields'][$key];
- } else {
- $group_attributes[$key] = $postdata[$key];
- }
+ $group_attributes[$key] = $gta['fields'][$key];
}
$group_attributes[$unique_attr] = $postdata[$unique_attr];
diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php
index 4695fdf..21276e2 100644
--- a/lib/api/kolab_api_service_user.php
+++ b/lib/api/kolab_api_service_user.php
@@ -65,7 +65,10 @@ class kolab_api_service_user extends kolab_api_service
if (isset($uta['form_fields'])) {
foreach ($uta['form_fields'] as $key => $value) {
- if (!isset($postdata[$key]) || empty($postdata[$key])) {
+ if (
+ (!isset($postdata[$key]) || empty($postdata[$key])) &&
+ !(array_key_exists('optional', $value) && $value['optional'])
+ ) {
throw new Exception("Missing input value for $key", 345);
}
else {
@@ -77,11 +80,13 @@ class kolab_api_service_user extends kolab_api_service
if (isset($uta['auto_form_fields'])) {
foreach ($uta['auto_form_fields'] as $key => $value) {
if (empty($postdata[$key])) {
- $postdata['attributes'] = array($key);
- $res = $form_service->generate($getdata, $postdata);
- $postdata[$key] = $res[$key];
+ if (!array_key_exists('optional', $value) || $value['optional']) {
+ $postdata['attributes'] = array($key);
+ $res = $form_service->generate($getdata, $postdata);
+ $postdata[$key] = $res[$key];
+ $user_attributes[$key] = $postdata[$key];
+ }
}
- $user_attributes[$key] = $postdata[$key];
}
}
@@ -164,7 +169,10 @@ class kolab_api_service_user extends kolab_api_service
if (isset($uta['form_fields'])) {
foreach ($uta['form_fields'] as $key => $value) {
- if (!isset($postdata[$key]) || empty($postdata[$key])) {
+ if (
+ (!isset($postdata[$key]) || empty($postdata[$key])) &&
+ !(array_key_exists('optional', $value) && $value['optional'])
+ ) {
throw new Exception("Missing input value for $key", 345);
}
else {
@@ -176,21 +184,21 @@ class kolab_api_service_user extends kolab_api_service
if (isset($uta['auto_form_fields'])) {
foreach ($uta['auto_form_fields'] as $key => $value) {
if (empty($postdata[$key])) {
- $postdata['attributes'] = array($key);
- $res = $form_service->generate($getdata, $postdata);
- $postdata[$key] = $res[$key];
+ if (!array_key_exists('optional', $value) || $value['optional']) {
+ $postdata['attributes'] = array($key);
+ $res = $form_service->generate($getdata, $postdata);
+ $postdata[$key] = $res[$key];
+ $user_attributes[$key] = $postdata[$key];
+ }
+ } else {
+ $user_attributes[$key] = $postdata[$key];
}
- $user_attributes[$key] = $postdata[$key];
}
}
if (isset($uta['fields'])) {
foreach ($uta['fields'] as $key => $value) {
- if (!isset($postdata[$key]) || empty($postdata[$key])) {
- $user_attributes[$key] = $uta['fields'][$key];
- } else {
- $user_attributes[$key] = $postdata[$key];
- }
+ $user_attributes[$key] = $uta['fields'][$key];
}
$user_attributes[$unique_attr] = $postdata[$unique_attr];