/** * Check the given data before saving. * If input not valid, the message to display can be fetched using get_error() * * @param array Assoziative array with data to save * @param boolean Try to fix/complete record automatically * @return boolean True if input is valid, False if not. */ public function validate(&$save_data, $autofix = false) { // validate e-mail addresses if (!parent::validate($save_data, $autofix)) { return false; } // check for name input if (empty($save_data['name'])) { $this->set_error(self::ERROR_VALIDATE, 'nonamewarning'); return false; } // Verify that the required fields are set. $missing = null; $ldap_data = $this->_map_data($save_data); foreach ($this->prop['required_fields'] as $fld) { if (!isset($ldap_data[$fld]) || $ldap_data[$fld] === '') { $missing[$fld] = 1; } } if ($missing) { // try to complete record automatically if ($autofix) { $sn_field = $this->fieldmap['surname']; $fn_field = $this->fieldmap['firstname']; $mail_field = $this->fieldmap['email']; // try to extract surname and firstname from displayname $name_parts = preg_split('/[\\s,.]+/', $save_data['name']); if ($sn_field && $missing[$sn_field]) { $save_data['surname'] = array_pop($name_parts); unset($missing[$sn_field]); } if ($fn_field && $missing[$fn_field]) { $save_data['firstname'] = array_shift($name_parts); unset($missing[$fn_field]); } // try to fix missing e-mail, very often on import // from vCard we have email:other only defined if ($mail_field && $missing[$mail_field]) { $emails = $this->get_col_values('email', $save_data, true); if (!empty($emails) && ($email = array_shift($emails))) { $save_data['email'] = $email; unset($missing[$mail_field]); } } } // TODO: generate message saying which fields are missing if (!empty($missing)) { $this->set_error(self::ERROR_VALIDATE, 'formincomplete'); return false; } } return true; }
/** * Check the given data before saving. * If input not valid, the message to display can be fetched using get_error() * * @param array Assoziative array with data to save * @param boolean Try to fix/complete record automatically * @return boolean True if input is valid, False if not. */ public function validate(&$save_data, $autofix = false) { // validate e-mail addresses $valid = parent::validate($save_data, $autofix); // require at least one e-mail address (syntax check is already done) if ($valid && !array_filter($this->get_col_values('email', $save_data, true))) { $this->set_error(self::ERROR_VALIDATE, 'noemailwarning'); $valid = false; } return $valid; }
/** * Check the given data before saving. * If input not valid, the message to display can be fetched using get_error() * * @param array Assoziative array with data to save * @param boolean Try to fix/complete record automatically * @return boolean True if input is valid, False if not. */ function validate(&$save_data, $autofix = false) { // validate e-mail addresses $valid = parent::validate($save_data, $autofix); // require at least one email address or a name // https://code.google.com/p/myroundcube/issues/detail?id=534 /* if($valid && !strlen($save_data['firstname'].$save_data['surname'].$save_data['name']) && !array_filter($this->get_col_values('email', $save_data, true))){ $this->set_error(self::ERROR_VALIDATE, 'noemailwarning'); $valid = false; } */ return $valid; }
/** * Check the given data before saving. * If input not valid, the message to display can be fetched using get_error() * * @param array Assoziative array with data to save * @param boolean Try to fix/complete record automatically * @return boolean True if input is valid, False if not. */ public function validate(&$save_data, $autofix = false) { // validate e-mail addresses $valid = parent::validate($save_data, $autofix); // require at least one email address or a name if ($valid && !strlen($save_data['firstname'] . $save_data['surname'] . $save_data['name']) && !array_filter($this->get_col_values('email', $save_data, true))) { $this->set_error(self::ERROR_VALIDATE, 'noemailwarning'); $valid = false; } return $valid; }