Created
April 5, 2025 10:07
-
-
Save heyJordanParker/34ce3f46f0fb98694aa97b07a7464391 to your computer and use it in GitHub Desktop.
Bricksforge Custom Action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Custom action handler for Bricksforge Pro Forms | |
| * | |
| * @param object $form The form object containing submitted data | |
| */ | |
| function handle_form_submission($form) { | |
| // Get all form fields | |
| $fields = $form->get_fields(); | |
| // Required fields validation | |
| $required_fields = [ | |
| 'form-field-name' => 'Name', | |
| 'form-field-email' => 'Email' | |
| ]; | |
| // Check for required fields | |
| foreach ($required_fields as $field => $label) { | |
| if (empty($fields[$field])) { | |
| $form->set_result([ | |
| 'action' => 'custom', | |
| 'type' => 'error', | |
| 'message' => "$label is required." | |
| ]); | |
| return; | |
| } | |
| } | |
| // Process the form data as needed | |
| $email = strtolower(trim($fields['form-field-email'])); | |
| $name = trim($fields['form-field-name']); | |
| // Your custom processing logic here | |
| // For example, you could: | |
| // - Save to database | |
| // - Send to external API | |
| // - Trigger other WordPress actions | |
| // Example of a successful response | |
| $form->set_result([ | |
| 'action' => 'custom', | |
| 'type' => 'success', | |
| 'message' => 'Thank you for your submission!' | |
| ]); | |
| // Example of redirecting after submission | |
| // $form->set_result([ | |
| // 'action' => 'redirect', | |
| // 'type' => 'redirect', | |
| // 'redirectTo' => 'https://example.com/thank-you' | |
| // ]); | |
| } | |
| // Register the custom action for Bricksforge Pro Forms | |
| add_action('bricksforge/pro_forms/custom_action', 'handle_form_submission'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment