پرش به محتویات

"Action: bricks/form/custom_action"

هنگام ارسال فرمی‌با action از نوع Custom اجرا می‌شود. با آن می‌توانید منطق PHP سفارشی برای پردازش ارسال فرم اجرا کنید.

پارامترها

  • $form (Bricks\Form): The form instance.

نمونه استفاده

add_action( 'bricks/form/custom_action', function( $form ) {
    // Get form fields
    $fields = $form->get_fields();

    // Get form settings
    $settings = $form->get_settings();

    // Get submitted data
    $form_data = $fields['formId'] ?? []; // Or retrieve specific field values

    // Perform custom logic, e.g., send to external API
    $name = isset( $fields['form-field-name'] ) ? $fields['form-field-name'] : '';

    if ( $name === 'Specific Name' ) {
        // Do something
        $form->set_result( [
            'type' => 'success', // or 'danger', 'info', 'warning'
            'message' => esc_html__( 'Custom action executed successfully.', 'bricks' ),
        ] );
    }
} );