PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.7.2
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.7.2
2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 All 96 releases
sureforms / TECHNICAL_OVERVIEW.md
TECHNICAL_OVERVIEW.md
394 lines 12.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 # SureForms Technical Overview
2
3 ## Introduction
4
5 SureForms is a modern WordPress form builder plugin that leverages the native WordPress block editor (Gutenberg) to provide an intuitive, no-code form building experience. This document provides a comprehensive technical overview of the plugin's architecture, components, and functionality.
6
7 ## Table of Contents
8
9 1. [](#plugin-architecturePlugin Architecture](#plugin-architecture](#plugin-architecture)
10 2. [](#core-componentsCore Components](#core-components](#core-components)
11 3. [](#database-structureDatabase Structure](#database-structure](#database-structure)
12 4. [](#form-building-systemForm Building System](#form-building-system](#form-building-system)
13 5. [](#form-submission-processForm Submission Process](#form-submission-process](#form-submission-process)
14 6. [](#ai-integrationAI Integration](#ai-integration](#ai-integration)
15 7. [](#security-featuresSecurity Features](#security-features](#security-features)
16 8. [](#extension-pointsExtension Points](#extension-points](#extension-points)
17 9. [](#performance-considerationsPerformance Considerations](#performance-considerations](#performance-considerations)
18 10. [](#future-developmentFuture Development](#future-development](#future-development)
19
20 ## Plugin Architecture
21
22 SureForms follows a modular architecture pattern with clear separation of concerns. The plugin is structured around several key components that interact through well-defined interfaces.
23
24 ### Directory Structure
25
26 ```
27 sureforms/
28 ├── admin/ # Admin-specific functionality
29 ├── api/ # REST API endpoints
30 ├── assets/ # CSS, JS, and other assets
31 ├── inc/ # Core functionality
32 │ ├── ai-form-builder/ # AI form generation
33 │ ├── blocks/ # Block registration
34 │ ├── compatibility/ # Theme/plugin compatibility
35 │ ├── database/ # Custom database tables
36 │ ├── email/ # Email notification system
37 │ ├── fields/ # Form field definitions
38 │ ├── global-settings/ # Global plugin settings
39 │ ├── lib/ # Third-party libraries
40 │ ├── page-builders/ # Page builder integrations
41 │ ├── single-form-settings/ # Form-specific settings
42 │ └── traits/ # Shared PHP traits
43 ├── languages/ # Internationalization files
44 ├── modules/ # Feature modules
45 │ ├── gutenberg/ # Gutenberg integration
46 │ └── quick-action-sidebar/ # Quick action UI
47 ├── src/ # JavaScript source files
48 │ ├── admin/ # Admin JS
49 │ ├── blocks/ # Block JS
50 │ ├── components/ # Reusable React components
51 │ ├── lib/ # JS libraries
52 │ ├── store/ # Redux store
53 │ ├── styles/ # SCSS files
54 │ └── utils/ # Utility functions
55 └── templates/ # Template files
56 ```
57
58 ### Initialization Flow
59
60 The plugin follows a structured initialization process:
61
62 1. `sureforms.php` - Main plugin file that defines constants and includes the plugin loader
63 2. `plugin-loader.php` - Initializes the plugin and registers core components
64 3. Core components are loaded through the `Plugin_Loader` class using autoloading
65 4. WordPress hooks are registered to integrate with the WordPress lifecycle
66
67 ```mermaid
68 graph TD
69 A[sureforms.php] --> B[plugin-loader.php]
70 B --> C[Plugin_Loader class]
71 C --> D[Register hooks]
72 C --> E[Autoload classes]
73 C --> F[Load textdomain]
74 D --> G[Init core components]
75 G --> H[Post_Types]
76 G --> I[Form_Submit]
77 G --> J[Block_Patterns]
78 G --> K[Frontend_Assets]
79 G --> L[AI_Form_Builder]
80 G --> M[Rest_Api]
81 ```
82
83 ## Core Components
84
85 ### Plugin_Loader
86
87 The central initialization class that bootstraps the plugin, registers hooks, and loads core components. It follows a singleton pattern to ensure only one instance exists.
88
89 ```php
90 class Plugin_Loader {
91 private static $instance = null;
92
93 public static function get_instance() {
94 if (null === self::$instance) {
95 self::$instance = new self();
96 do_action('srfm_core_loaded');
97 }
98 return self::$instance;
99 }
100
101 // Initialization methods...
102 }
103 ```
104
105 ### Post_Types
106
107 Registers and manages custom post types for forms and entries. Handles the admin UI customizations for these post types.
108
109 Key features:
110 - Registers `sureforms_form` post type for storing form configurations
111 - Adds custom columns to the admin list view
112 - Implements shortcode functionality
113 - Manages form metadata registration
114
115 ### Form_Submit
116
117 Processes form submissions through REST API endpoints, validates input data, handles file uploads, processes anti-spam measures, and triggers email notifications.
118
119 Key features:
120 - Registers `/sureforms/v1/submit-form` REST API endpoint
121 - Validates form submissions against defined rules
122 - Processes file uploads with security checks
123 - Handles anti-spam measures (honeypot, reCAPTCHA, hCaptcha, Cloudflare Turnstile)
124 - Stores submissions in the database
125 - Triggers email notifications
126
127 ### AI_Form_Builder
128
129 Integrates with AI services to generate form structures based on user prompts. Communicates with middleware services to process AI requests.
130
131 Key features:
132 - Processes natural language descriptions into form structures
133 - Maps AI-generated fields to SureForms field types
134 - Generates block structures for the editor
135
136 ## Database Structure
137
138 SureForms uses both WordPress custom post types and custom database tables to store data efficiently.
139
140 ### Custom Post Types
141
142 - **sureforms_form**: Stores form configurations
143 - Post content: Serialized blocks representing the form structure
144 - Post meta: Form settings, styling options, and other configuration data
145
146 ### Custom Database Tables
147
148 - **{prefix}_srfm_entries**: Stores form submissions
149 - ID: Primary key
150 - form_id: Associated form ID
151 - user_id: Submitter's user ID (if logged in)
152 - form_data: JSON-encoded submission data
153 - submission_info: Browser, IP, and device information
154 - status: Entry status (read, unread, trash)
155 - logs: Activity logs for the entry
156 - created_at: Submission timestamp
157
158 ```mermaid
159 erDiagram
160 FORMS ||--o{ ENTRIES : "has"
161 FORMS {
162 int ID
163 string post_title
164 text post_content
165 string post_status
166 datetime post_date
167 }
168 ENTRIES {
169 int ID
170 int form_id
171 int user_id
172 json form_data
173 json submission_info
174 string status
175 json logs
176 datetime created_at
177 }
178 FORMS ||--o{ FORM_META : "has"
179 FORM_META {
180 int meta_id
181 int post_id
182 string meta_key
183 mixed meta_value
184 }
185 ```
186
187 ## Form Building System
188
189 SureForms uses WordPress's block editor as the foundation for its form builder.
190
191 ### Block Structure
192
193 Forms are composed of various block types:
194
195 - **Container Blocks**: Group and organize form fields
196 - **Field Blocks**: Individual form inputs (text, email, checkbox, etc.)
197 - **Layout Blocks**: Control the visual arrangement of fields
198 - **Special Blocks**: Submit buttons, GDPR notices, etc.
199
200 Each block has its own edit and save components, following the WordPress block API pattern.
201
202 ### Block Registration
203
204 Blocks are registered using the WordPress block registration API:
205
206 ```javascript
207 registerBlockType('sureforms/input', {
208 title: __('Text Field', 'sureforms'),
209 icon: 'text',
210 category: 'sureforms',
211 attributes: {
212 // Block attributes
213 },
214 edit: Edit,
215 save: Save
216 });
217 ```
218
219 ### Form Rendering
220
221 Forms are rendered on the frontend using a combination of server-side rendering and client-side JavaScript:
222
223 1. The form shortcode or block triggers the `Generate_Form_Markup::get_form_markup()` method
224 2. The method retrieves the form configuration and generates the HTML markup
225 3. Frontend JavaScript initializes the form functionality (validation, submission, etc.)
226
227 ## Form Submission Process
228
229 ### Client-Side Flow
230
231 1. User fills out the form
232 2. Client-side validation checks for errors
233 3. Form data is collected and serialized
234 4. AJAX request is sent to the REST API endpoint
235 5. Response is processed and appropriate feedback is shown to the user
236
237 ### Server-Side Flow
238
239 1. REST API endpoint receives the form submission
240 2. Data is validated and sanitized
241 3. Anti-spam checks are performed
242 4. If GDPR compliance is enabled, appropriate data handling is applied
243 5. Submission is stored in the database (unless configured not to)
244 6. Email notifications are triggered
245 7. Response is sent back to the client
246
247 ```mermaid
248 sequenceDiagram
249 participant User
250 participant Browser
251 participant REST_API
252 participant Database
253 participant Email
254
255 User->>Browser: Fill form
256 Browser->>Browser: Validate input
257 User->>Browser: Submit form
258 Browser->>REST_API: POST /sureforms/v1/submit-form
259 REST_API->>REST_API: Validate data
260 REST_API->>REST_API: Anti-spam check
261 REST_API->>Database: Store submission
262 REST_API->>Email: Send notifications
263 REST_API->>Browser: Return response
264 Browser->>User: Show confirmation
265 ```
266
267 ## AI Integration
268
269 SureForms features an AI-powered form generation system that allows users to create forms by describing them in natural language.
270
271 ### AI Form Generation Process
272
273 1. User provides a description of the desired form
274 2. The description is sent to the AI middleware
275 3. AI analyzes the description and generates a structured form definition
276 4. The form definition is mapped to SureForms field types
277 5. Blocks are generated and inserted into the editor
278 6. User can review and modify the generated form
279
280 ### AI Middleware
281
282 The AI middleware acts as a bridge between SureForms and the AI service:
283
284 1. Receives the form description from SureForms
285 2. Processes the description using AI models
286 3. Returns a structured form definition
287 4. Handles authentication and rate limiting
288
289 ## Security Features
290
291 SureForms implements multiple security measures to protect against common vulnerabilities:
292
293 ### Anti-Spam Protection
294
295 - **Honeypot Fields**: Hidden fields to catch automated submissions
296 - **reCAPTCHA Integration**: Multiple versions of Google reCAPTCHA
297 - **hCaptcha Support**: Alternative to reCAPTCHA
298 - **Cloudflare Turnstile**: Modern CAPTCHA alternative
299
300 ### Data Protection
301
302 - **GDPR Compliance**: Options to enable GDPR-compliant data handling
303 - **Data Encryption**: Sensitive data can be encrypted in storage
304 - **Auto-Delete Entries**: Automatic deletion of entries after a specified period
305
306 ### Input Validation
307
308 - **Client-Side Validation**: Immediate feedback to users
309 - **Server-Side Validation**: Thorough validation of all submitted data
310 - **File Upload Security**: Strict file type and size validation
311
312 ## Extension Points
313
314 SureForms provides several extension points for developers:
315
316 ### WordPress Hooks
317
318 ```php
319 // Example of filter hook for email notification
320 add_filter('srfm_email_notification', function($parsed, $submission_data, $item, $form_data) {
321 // Modify email content or recipients
322 return $parsed;
323 }, 10, 4);
324
325 // Example of action hook before form submission
326 add_action('srfm_before_submission', function($form_data) {
327 // Perform custom actions before form processing
328 });
329 ```
330
331 ### JavaScript API
332
333 ```javascript
334 // Example of extending the form validation
335 window.sureFormsHooks.addFilter(
336 'srfm.validation.rules',
337 'my-plugin/custom-validation',
338 function(rules, fieldData) {
339 // Add custom validation rules
340 return rules;
341 }
342 );
343 ```
344
345 ## Performance Considerations
346
347 SureForms is designed with performance in mind:
348
349 ### Asset Loading
350
351 - CSS and JavaScript assets are loaded only when needed
352 - Assets are minified and optimized for production
353 - Critical CSS is inlined for faster rendering
354
355 ### Database Optimization
356
357 - Custom database tables with appropriate indexes
358 - Efficient queries with proper WHERE clauses
359 - Caching of frequently accessed data
360
361 ### Form Rendering
362
363 - Server-side rendering for initial form display
364 - Progressive enhancement for JavaScript features
365 - Lazy loading of heavy components
366
367 ## Future Development
368
369 Planned enhancements for future versions:
370
371 1. **Enhanced AI Capabilities**
372 - More sophisticated form generation
373 - AI-powered form analytics
374
375 2. **Advanced Integrations**
376 - More third-party service integrations
377 - Improved CRM connections
378
379 3. **Performance Optimizations**
380 - Further asset optimization
381 - Enhanced caching strategies
382
383 4. **Accessibility Improvements**
384 - Better screen reader support
385 - Keyboard navigation enhancements
386
387 5. **Developer Tools**
388 - More comprehensive API documentation
389 - Additional extension points
390
391 ## Conclusion
392
393 SureForms represents a modern approach to WordPress form building, combining the power of the block editor with advanced features like AI form generation. Its modular architecture and extensive extension points make it both user-friendly and developer-friendly, while its focus on security and performance ensures a reliable experience for all users.
394