Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save heyJordanParker/34ce3f46f0fb98694aa97b07a7464391 to your computer and use it in GitHub Desktop.

Select an option

Save heyJordanParker/34ce3f46f0fb98694aa97b07a7464391 to your computer and use it in GitHub Desktop.
Bricksforge Custom Action
/**
* 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