Fodo Docs
Forms

Hooks & Filters

Customize Fodo Forms behavior with WordPress hooks

Hooks & Filters

Fodo Forms provides WordPress action hooks and filters to customize behavior, modify data, and extend functionality.

Form rendering

fodo_forms_before_form

Fires before the form element is rendered.

add_action('fodo_forms_before_form', function($form) {
    echo '<div class="my-form-wrapper">';
}, 10, 1);

Parameters:

  • $form (array) - Form configuration

fodo_forms_after_form

Fires after the form element is rendered.

add_action('fodo_forms_after_form', function($form) {
    echo '</div><!-- .my-form-wrapper -->';
}, 10, 1);

fodo_forms_field_attributes

Filter field wrapper attributes.

add_filter('fodo_forms_field_attributes', function($attrs, $field, $form) {
    // Add custom data attribute
    $attrs['data-analytics'] = 'field-' . $field['id'];
    return $attrs;
}, 10, 3);

Parameters:

  • $attrs (array) - HTML attributes
  • $field (array) - Field configuration
  • $form (array) - Form configuration

fodo_forms_field_html

Filter the complete field HTML output.

add_filter('fodo_forms_field_html', function($html, $field, $form) {
    // Wrap all email fields with extra markup
    if ($field['type'] === 'email') {
        $html = '<div class="email-field-wrapper">' . $html . '</div>';
    }
    return $html;
}, 10, 3);

Form submission

fodo_forms_before_submission

Fires before submission is processed. Return modified data.

add_filter('fodo_forms_before_submission', function($data, $form) {
    // Add server-side timestamp
    $data['fields']['server_time'] = current_time('mysql');

    // Sanitize or transform fields
    if (isset($data['fields']['phone'])) {
        $data['fields']['phone'] = preg_replace('/[^0-9]/', '', $data['fields']['phone']);
    }

    return $data;
}, 10, 2);

Parameters:

  • $data (array) - Submission data with fields key
  • $form (array) - Form configuration

fodo_forms_after_submission

Fires after successful submission.

add_action('fodo_forms_after_submission', function($entry_id, $data, $form) {
    // Log to external service
    wp_remote_post('https://api.example.com/log', [
        'body' => json_encode([
            'entry_id' => $entry_id,
            'form' => $form['title'],
        ])
    ]);

    // Trigger custom action
    do_action('my_custom_form_submitted', $entry_id);
}, 10, 3);

Parameters:

  • $entry_id (int) - Created entry ID
  • $data (array) - Submission data
  • $form (array) - Form configuration

fodo_forms_validation_errors

Filter validation errors before returning to user.

add_filter('fodo_forms_validation_errors', function($errors, $data, $form) {
    // Custom validation
    if (isset($data['fields']['age']) && $data['fields']['age'] < 18) {
        $errors['age'] = 'You must be at least 18 years old.';
    }

    // Cross-field validation
    if ($data['fields']['password'] !== $data['fields']['confirm_password']) {
        $errors['confirm_password'] = 'Passwords do not match.';
    }

    return $errors;
}, 10, 3);

Email notifications

fodo_forms_notification_to

Filter notification recipients.

add_filter('fodo_forms_notification_to', function($to, $data, $form) {
    // Route to different department based on selection
    $department = $data['fields']['department'] ?? 'general';

    $emails = [
        'sales' => 'sales@example.com',
        'support' => 'support@example.com',
        'billing' => 'billing@example.com',
        'general' => 'info@example.com',
    ];

    return $emails[$department] ?? $to;
}, 10, 3);

fodo_forms_notification_subject

Filter email subject line.

add_filter('fodo_forms_notification_subject', function($subject, $data, $form) {
    // Add priority indicator
    if (($data['fields']['priority'] ?? '') === 'urgent') {
        $subject = '[URGENT] ' . $subject;
    }
    return $subject;
}, 10, 3);

fodo_forms_notification_message

Filter email body content.

add_filter('fodo_forms_notification_message', function($message, $data, $form) {
    // Add footer to all notification emails
    $message .= "\n\n---\n";
    $message .= "This email was sent from " . home_url();
    return $message;
}, 10, 3);

fodo_forms_notification_headers

Filter email headers.

add_filter('fodo_forms_notification_headers', function($headers, $data, $form) {
    // Add CC
    $headers[] = 'Cc: manager@example.com';

    // Add custom header
    $headers[] = 'X-Form-ID: ' . $form['id'];

    return $headers;
}, 10, 3);

Field registration

fodo_forms_register_fields

Register custom field types.

add_action('fodo_forms_register_fields', function($registry) {
    $registry->registerType('rating', [
        'label' => 'Star Rating',
        'icon' => 'Star',
        'category' => 'advanced',
    ]);
});

See Custom Fields for full implementation.

fodo_forms_builder_config

Add data to the form builder JavaScript.

add_filter('fodo_forms_builder_config', function($config) {
    // Add custom field options
    $config['customOptions'] = [
        'currencies' => ['USD', 'EUR', 'GBP'],
    ];

    return $config;
});

Entries

fodo_forms_entry_saved

Fires when entry is saved to database.

add_action('fodo_forms_entry_saved', function($entry_id, $form_id, $data) {
    // Sync to external database
    sync_to_external_db($entry_id, $data);
}, 10, 3);

fodo_forms_entry_deleted

Fires when entry is deleted.

add_action('fodo_forms_entry_deleted', function($entry_id) {
    // Clean up external references
    delete_external_reference($entry_id);
});

Assets

fodo_forms_enqueue_scripts

Fires when form scripts are enqueued.

add_action('fodo_forms_enqueue_scripts', function() {
    // Add custom scripts
    wp_enqueue_script(
        'my-form-enhancements',
        get_template_directory_uri() . '/js/forms.js',
        ['fodo-forms-frontend'],
        '1.0.0',
        true
    );
});

fodo_forms_frontend_css

Filter inline CSS added to frontend.

add_filter('fodo_forms_frontend_css', function($css) {
    // Add theme-specific overrides
    $css .= '.fodo-form { font-family: inherit; }';
    return $css;
});

Pro hooks

fodo_forms_payment_complete

Fires when payment is successful.

add_action('fodo_forms_payment_complete', function($entry_id, $payment_data, $form) {
    // Send to accounting system
    send_to_accounting([
        'amount' => $payment_data['amount'],
        'transaction_id' => $payment_data['transaction_id'],
        'customer_email' => $payment_data['email'],
    ]);
}, 10, 3);

fodo_forms_integration_data

Filter data sent to integrations.

add_filter('fodo_forms_integration_data', function($data, $integration, $form) {
    // Add tracking info for all integrations
    $data['source'] = 'website_form';
    $data['campaign'] = $_GET['utm_campaign'] ?? '';

    return $data;
}, 10, 3);

Complete example

Custom form processing with multiple hooks:

<?php
/**
 * Custom form processing for contact form
 */

// Validate company email domain
add_filter('fodo_forms_validation_errors', function($errors, $data, $form) {
    if ($form['slug'] !== 'enterprise-contact') {
        return $errors;
    }

    $email = $data['fields']['email'] ?? '';
    $blocked = ['gmail.com', 'yahoo.com', 'hotmail.com'];

    $domain = substr(strrchr($email, '@'), 1);
    if (in_array($domain, $blocked)) {
        $errors['email'] = 'Please use your company email address.';
    }

    return $errors;
}, 10, 3);

// Route to sales rep based on company size
add_filter('fodo_forms_notification_to', function($to, $data, $form) {
    if ($form['slug'] !== 'enterprise-contact') {
        return $to;
    }

    $employees = (int) ($data['fields']['employees'] ?? 0);

    if ($employees > 1000) {
        return 'enterprise@example.com';
    } elseif ($employees > 100) {
        return 'midmarket@example.com';
    }

    return 'sales@example.com';
}, 10, 3);

// Create lead in CRM
add_action('fodo_forms_after_submission', function($entry_id, $data, $form) {
    if ($form['slug'] !== 'enterprise-contact') {
        return;
    }

    $crm = new MyCRM();
    $crm->createLead([
        'name' => $data['fields']['name'],
        'email' => $data['fields']['email'],
        'company' => $data['fields']['company'],
        'employees' => $data['fields']['employees'],
        'source' => 'enterprise_form',
        'entry_id' => $entry_id,
    ]);
}, 10, 3);