From 3d8b54edf74792e3996d861a6a30c41d82976261 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Tue, 12 Apr 2011 14:05:36 -0400
Subject: [PATCH] Keep all submitted data if contact form validation fails (#1487865)

---
 CHANGELOG                          |    2 ++
 program/steps/addressbook/edit.inc |   38 +++++++++++++++++++++-----------------
 program/steps/addressbook/save.inc |    1 +
 3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 626b3fc..33e4be8 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,8 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Keep all submitted data if contact form validation fails (#1487865)
+- Handle uncode strings in rcube_addressbook::normalize_string() (#1487866)
 - Fix bug where template name without plugin prefix was used in render_page hook
 - Fix handling of debug_level=4 in ajax requests (#1487831)
 - Support 'abort' and 'result' response in 'preferences_save' hook, add error handling
diff --git a/program/steps/addressbook/edit.inc b/program/steps/addressbook/edit.inc
index 932dc49..cf6beba 100644
--- a/program/steps/addressbook/edit.inc
+++ b/program/steps/addressbook/edit.inc
@@ -31,18 +31,28 @@
 }
 
 
+function rcmail_get_edit_record()
+{
+    global $RCMAIL, $CONTACTS;
+
+     // check if we have a valid result
+     if ($GLOBALS['EDIT_RECORD']) {
+         $record = $GLOBALS['EDIT_RECORD'];
+     }
+     else if ($RCMAIL->action != 'add'
+         && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))
+     ) {
+         $RCMAIL->output->show_message('contactnotfound');
+         return false;
+     }
+     
+     return $record;
+}
+
 function rcmail_contact_edithead($attrib)
 {
-   global $RCMAIL, $CONTACTS;
-
     // check if we have a valid result
-    if ($RCMAIL->action != 'add'
-        && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))
-    ) {
-        $RCMAIL->output->show_message('contactnotfound');
-        return false;
-    }
-    
+    $record = rcmail_get_edit_record();
     $i_size = !empty($attrib['size']) ? $attrib['size'] : 20;
 
     $form = array(
@@ -74,15 +84,9 @@
 
 function rcmail_contact_editform($attrib)
 {
-   global $RCMAIL, $CONTACTS, $CONTACT_COLTYPES;
+    global $RCMAIL, $CONTACT_COLTYPES;
 
-    // check if we have a valid result
-    if ($RCMAIL->action != 'add'
-        && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))
-    ) {
-        $RCMAIL->output->show_message('contactnotfound');
-        return false;
-    }
+    $record = rcmail_get_edit_record();
 
     // add some labels to client
     $RCMAIL->output->add_label('noemailwarning', 'nonamewarning');
diff --git a/program/steps/addressbook/save.inc b/program/steps/addressbook/save.inc
index 8949a23..88fe98c 100644
--- a/program/steps/addressbook/save.inc
+++ b/program/steps/addressbook/save.inc
@@ -139,6 +139,7 @@
 if (!$CONTACTS->validate($a_record)) {
     $err = (array)$CONTACTS->get_error() + array('message' => 'formincomplete', 'type' => 'warning');
     $OUTPUT->show_message($err['message'], $err['type']);
+    $GLOBALS['EDIT_RECORD'] = $a_record;  // store submitted data to be used in edit form
     rcmail_overwrite_action($return_action);
     return;
 }

--
Gitblit v1.9.1