Jake Vanderwerf
7 days ago 46d681c6b825d21b3f698d793c4e630c687d90ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
/**
 * Form Block Render
 *
 * @package Edmonton_Ink
 */
 
/**
 * Renders the form block on the frontend
 *
 * @param array    $attributes The block attributes.
 * @param string   $content    The block content.
 * @param WP_Block $block      The block instance.
 * @return string The rendered output.
 */
function jvbRenderFormBlock(array $attributes, string $content, WP_Block $block):string
{
    // Get form type from attributes
    $form_type = isset($attributes['formType']) ? $attributes['formType'] : '';
 
    // If no form type selected, return a message
    if (empty($form_type)) {
        return '<div class="jvb-form-error">No form type selected. Please edit this block and select a form type.</div>';
    }
 
    // Get other attributes
    $show_labels = isset($attributes['showLabels']) ? $attributes['showLabels'] : true;
    $custom_email_to = isset($attributes['customEmailTo']) ? $attributes['customEmailTo'] : '';
 
    // Set custom options for the form
    $form_options = array();
 
    // Set custom email recipient if provided
    if (!empty($custom_email_to)) {
        $form_options['email_to'] = $custom_email_to;
    }
 
    // Render the form with the specified options
    $form_output = JVB()->forms()->renderForm($form_type);
 
    // Get block classes
    $wrapper_attributes = get_block_wrapper_attributes([
        'class' => 'jvb-forms'
    ]);
 
    // Return the wrapped form
    return sprintf(
        '<div %1$s>%2$s</div>',
        $wrapper_attributes,
        $form_output
    );
}