Index: branches/5.2.x/core/units/forms/forms/forms_eh.php =================================================================== diff -u -N -r14244 -r14596 --- branches/5.2.x/core/units/forms/forms/forms_eh.php (.../forms_eh.php) (revision 14244) +++ branches/5.2.x/core/units/forms/forms/forms_eh.php (.../forms_eh.php) (revision 14596) @@ -1,6 +1,6 @@ status == kEvent::erSUCCESS) { + if ( $event->status == kEvent::erSUCCESS ) { $this->OnCreateFormFields($event); - $this->_deleteSectionCache(); } } - function OnMassDelete(&$event) + /** + * Deletes all selected items. + * Automatically recurse into sub-items using temp handler, and deletes sub-items + * by calling its Delete method if sub-item has AutoDelete set to true in its config file + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnMassDelete(&$event) { parent::OnMassDelete($event); - if ($event->status == kEvent::erSUCCESS) { + if ( $event->status == kEvent::erSUCCESS ) { $this->_deleteSectionCache(); } } @@ -116,7 +132,7 @@ } /** - * Dynamically fills customdata config + * Dynamically fills custom data config * * @param kEvent $event */ @@ -157,41 +173,47 @@ * Enter description here... * * @param kEvent $event + * @return void + * @access protected */ - function OnFormSubmit(&$event) + protected function OnFormSubmit(&$event) { - $object =& $event->GetObject(); + $object =& $event->getObject(); + /* @var $object kDBItem */ $fields = explode(',',$this->Application->GetVar('fields')); $required_fields = explode(',', $this->Application->GetVar('required_fields')); $fields_params = $this->Application->GetVar('fields_params'); + $virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields'); + foreach ($fields as $field) { - $virt_fields[$field] = Array(); - if (in_array($field, $required_fields)) { - $virt_fields[$field]['required'] = 1; + $virtual_fields[$field] = Array (); + + if ( in_array($field, $required_fields) ) { + $virtual_fields[$field]['required'] = 1; } + $params = getArrayValue($fields_params, $field); - if ($params !== false) { - if (getArrayValue($params, 'Type') == 'email') { - //'formatter'=>'kFormatter', 'regexp'=>'/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', 'error_msgs' => Array('invalid_format'=>'!la_invalid_email!') - $virt_fields[$field]['formatter'] = 'kFormatter'; - $virt_fields[$field]['regexp'] = '/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i'; - $virt_fields[$field]['error_msgs'] = Array('invalid_format'=>'!la_invalid_email!'); + + if ( $params !== false ) { + if ( getArrayValue($params, 'Type') == 'email' ) { + $virtual_fields[$field]['formatter'] = 'kFormatter'; + $virtual_fields[$field]['regexp'] = '/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i'; + $virtual_fields[$field]['error_msgs'] = Array ('invalid_format' => '!la_invalid_email!'); } - if (getArrayValue($params, 'Type') == 'file') { - $virt_fields[$field]['formatter'] = 'kUploadFormatter'; - $virt_fields[$field]['upload_dir'] = '/uploads/sketches/'; + + if ( getArrayValue($params, 'Type') == 'file' ) { + $virtual_fields[$field]['formatter'] = 'kUploadFormatter'; + $virtual_fields[$field]['upload_dir'] = '/uploads/sketches/'; } } } - $object->SetVirtualFields($virt_fields); + $object->SetVirtualFields($virtual_fields); $field_values = $this->getSubmittedFields($event); + $checkboxes = explode(',', $this->Application->GetVar('checkbox_fields')); // MailingList,In-Link,In-Newz,In-Bulletin - - $checkboxes = Array('MailingList', 'In-Link', 'In-Newz', 'In-Bulletin'); - $checkboxes = explode(',', $this->Application->GetVar('checkbox_fields')); foreach ($checkboxes as $checkbox) { if (isset($field_values[$checkbox])) { $field_values[$checkbox] = 1; @@ -202,16 +224,21 @@ } $object->SetFieldsFromHash($field_values); - if ($object->Validate()) { + + if ( $object->Validate() ) { $event->redirect = $this->Application->GetVar('success_template'); $this->Application->EmailEventAdmin($this->Application->GetVar('email_event')); - $this->Application->EmailEventUser($this->Application->GetVar('email_event'), null, - Array('to_email' => $field_values[$this->Application->GetVar('email_field')], - 'to_name' => $field_values[$this->Application->GetVar('name_field')])); - if ($field_values['MailingList']) { + $send_params = Array ( + 'to_email' => $field_values[$this->Application->GetVar('email_field')], + 'to_name' => $field_values[$this->Application->GetVar('name_field')] + ); + + $this->Application->EmailEventUser($this->Application->GetVar('email_event'), null, $send_params); + + if ( $field_values['MailingList'] ) { $this->Application->StoreVar('SubscriberEmail', $field_values['Email']); - $this->Application->HandleEvent($sub_event, 'u:OnSubscribeUser', Array('no_unsubscribe' => 1)); + $this->Application->HandleEvent($sub_event, 'u:OnSubscribeUser', Array ('no_unsubscribe' => 1)); } } else { @@ -223,25 +250,37 @@ * Don't use security image, when form requires login * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { parent::OnBeforeItemCreate($event); - $this->_validatePopSettings($event); - $this->_disableSecurityImage($event); - $this->_setRequired($event); + $this->itemChanged($event); } /** * Don't use security image, when form requires login * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { parent::OnBeforeItemUpdate($event); + $this->itemChanged($event); + } + + /** + * Occurs before item is changed + * + * @param kEvent $event + */ + function itemChanged(&$event) + { $this->_validatePopSettings($event); $this->_disableSecurityImage($event); $this->_setRequired($event); @@ -327,9 +366,7 @@ $fields = array_merge($fields, $bounce_fields); } - foreach ($fields as $field) { - $object->setRequired($field, $required); - } + $object->setRequired($fields, $required); } /**