# suredonation/1.1.0/inc/fields/form-renderer.php

SureDonation – Donation Forms, Fundraising Campaigns &amp; Donor Management, version 1.1.0. 84 lines.

- Page: https://pluginprobe.com/plugins/suredonation/1.1.0/code/inc/fields/form-renderer.php
- Raw: https://pluginprobe.com/plugins/suredonation/1.1.0/raw/inc/fields/form-renderer.php
- Modified: 2026-06-25T09:15:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/suredonation/1.1.0/code/inc/fields/form-renderer.php#L10-L20`.

```php
<?php
/**
 * Donation form markup renderer.
 *
 * Shared by the donation-form block and the [suredonation_form] shortcode so
 * both produce identical markup (wrapper, form, field blocks, success box) and
 * pick up per-form styling from a single place.
 *
 * Callers handle validation, campaign resolution, and asset enqueueing; this
 * class only builds the markup.
 *
 * @package SureDonation
 * @since 1.0.0
 */

namespace SureDonation\Inc\Fields;

use SureDonation\Inc\Helper;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Form_Renderer class.
 *
 * @since 1.0.0
 */
class Form_Renderer {

	/**
	 * Render the donation form markup for a form + campaign.
	 *
	 * @param \WP_Post $form        Donation form post.
	 * @param int      $campaign_id Resolved campaign ID (0 for a standalone form).
	 * @return string Form HTML.
	 * @since 1.0.0
	 */
	public static function render( $form, $campaign_id ) {
		if ( ! $form instanceof \WP_Post ) {
			return '';
		}

		$form_id        = (int) $form->ID;
		$campaign_id    = (int) $campaign_id;
		$unique_form_id = 'suredonation-form-' . $form_id . '-' . wp_rand();
		$form_style     = Form_Styling::get_style_attr( $form_id );
		$nonce_action   = Helper::get_donation_nonce_action( $campaign_id );
		$blocks         = parse_blocks( $form->post_content );

		ob_start();
		?>
		<div id="<?php echo esc_attr( $unique_form_id ); ?>" class="sd-form-container" data-form-id="<?php echo esc_attr( (string) $form_id ); ?>" data-campaign-id="<?php echo esc_attr( (string) $campaign_id ); ?>"<?php echo '' !== $form_style ? ' style="' . esc_attr( $form_style ) . '"' : ''; ?>>
			<form class="sd-form" method="post">
				<?php wp_nonce_field( $nonce_action, 'suredonation_nonce' ); ?>
				<input type="hidden" name="form_id" value="<?php echo esc_attr( (string) $form_id ); ?>">
				<input type="hidden" name="campaign_id" value="<?php echo esc_attr( (string) $campaign_id ); ?>">
				<?php if ( ! $campaign_id ) { ?>
				<input type="hidden" name="is_standalone" value="1">
				<?php } ?>
				<input type="hidden" name="action" value="suredonation_submit_donation">
				<?php Helper::render_honeypot_field(); ?>

				<?php
				foreach ( $blocks as $block ) {
					if ( empty( $block['blockName'] ) ) {
						continue;
					}
					$block['attrs']['formId'] = $form_id;
					echo wp_kses( render_block( $block ), Helper::get_allowed_form_html() );
				}
				?>
			</form>
			<!-- Success Message Container -->
			<div class="sd-single-form sd-success-box">
				<div aria-live="polite" aria-atomic="true" role="alert" id="sd-success-message-<?php echo esc_attr( (string) $form_id ); ?>" class="sd-success-box-description"></div>
			</div>
		</div>
		<?php
		$output = ob_get_clean();
		return false !== $output ? $output : '';
	}
}

```
