| | |
| | | use JVBase\meta\Validator; |
| | | use JVBase\rest\PermissionHandler; |
| | | use JVBase\rest\Rest; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\blocks\FormBlock; |
| | | use JVBase\rest\Route; |
| | | use JVBase\base\Site; |
| | |
| | | if (is_wp_error($result)) { |
| | | return $this->error( |
| | | $result->get_error_message(), |
| | | $result->get_error_code(), |
| | | 400 |
| | | $result->get_error_code() |
| | | ); |
| | | } |
| | | if (array_key_exists('success', $result)){ |
| | |
| | | if (!empty($files)) { |
| | | try { |
| | | $files = $this->validateFileUploads($files, $form_config); |
| | | } catch (\Exception $e) { |
| | | } catch (Exception $e) { |
| | | return new WP_Error('file_validation_failed', 'File validation error: ' . $e->getMessage()); |
| | | } |
| | | } |
| | |
| | | // Validate and sanitize form data |
| | | try { |
| | | $processed_data = $this->validateAndSanitizeData($form_config, $form_data); |
| | | } catch (\Exception $e) { |
| | | } catch (Exception $e) { |
| | | return new WP_Error('validation_failed', 'Data validation error: ' . $e->getMessage()); |
| | | } |
| | | if (array_key_exists('success', $processed_data) && $processed_data['success'] === false) { |
| | |
| | | // Send email notification with attachments |
| | | try { |
| | | $email_sent = $this->sendEmailNotification($form_type, $form_config, $processed_data, $files); |
| | | } catch (\Exception $e) { |
| | | } catch (Exception $e) { |
| | | return new WP_Error('email_failed', 'Email error: ' . $e->getMessage()); |
| | | } |
| | | |
| | |
| | | ]; |
| | | } |
| | | |
| | | $body .= Emails::getInstance()->spacer(20); |
| | | $body .= Emails::getInstance()->spacer(); |
| | | $body .= Emails::getInstance()->table($form); |
| | | |
| | | // Show attachment info |
| | |
| | | if (!empty($attachments)) { |
| | | $body .= Emails::getInstance()->spacer(10); |
| | | $body .= Emails::getInstance()->alert( |
| | | sprintf('%d file(s) attached to this email', count($attachments)), |
| | | 'info' |
| | | sprintf('%d file(s) attached to this email', count($attachments)) |
| | | ); |
| | | } |
| | | |
| | |
| | | $forms = FormBlock::getForms(); |
| | | |
| | | // Remove sensitive data |
| | | $public_forms = []; |
| | | foreach ($forms as $key => $config) { |
| | | $public_forms[$key] = [ |
| | | // Remove sensitive configuration |
| | | $public_forms = array_map(function ($config) use ($field) { |
| | | return [ |
| | | 'title' => $config['title'], |
| | | 'description' => $config['description'], |
| | | 'fields' => array_map(function($field) { |
| | | 'fields' => array_map(function ($field) { |
| | | // Remove sensitive configuration |
| | | unset($field['email_to']); |
| | | return $field; |
| | | }, $config['fields']) |
| | | ]; |
| | | } |
| | | }, $forms); |
| | | |
| | | return $this->success($public_forms); |
| | | } |