| New file |
| | |
| | | <?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 |
| | | ); |
| | | } |