From 42fa8304ddb811b0f725f245130f70c0f5e86a6c Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 04 Nov 2025 06:12:02 +0000
Subject: [PATCH] =Refactored LoginManager to be more extensible and configurable, as well as an AjaxRateLimiter
---
inc/blocks/FormBlock.php | 67 +++++++++++++++++++--------------
1 files changed, 38 insertions(+), 29 deletions(-)
diff --git a/inc/blocks/FormBlock.php b/inc/blocks/FormBlock.php
index 6cec6de..640368a 100644
--- a/inc/blocks/FormBlock.php
+++ b/inc/blocks/FormBlock.php
@@ -35,7 +35,7 @@
public function __construct()
{
- $this->cache = new CacheManager('form_blocks', HOUR_IN_SECONDS);
+ $this->cache = CacheManager::for('form_blocks', WEEK_IN_SECONDS);
// Initialize forms from filter
$this->forms = $this->registerForms();
@@ -46,7 +46,6 @@
// Register forms data for the block editor
add_action('enqueue_block_editor_assets', [$this, 'localizeFormsData']);
-
add_action('init', [$this, 'registerBlock']);
}
@@ -112,7 +111,7 @@
$cache_key = $this->cache->generateKey($block);
$cached = $this->cache->get($cache_key);
-
+ $cached = false;
if ($cached) {
return $cached;
}
@@ -285,10 +284,13 @@
if (!empty($form_config['sections'])) {
$this->renderSections($type, $meta);
} else {
+ echo jvbFormStatus();
// Render fields directly
foreach ($form_config['fields'] as $field_name => $field_config) {
$meta->render('form', $field_name, $field_config);
}
+ $submit_text = $form_config['submit'] ?? 'Submit';
+ echo '<button type="submit" class="button primary">' . esc_html($submit_text) . '</button>';
}
}
@@ -300,8 +302,14 @@
$form_config = $this->forms[$type];
$sections = $form_config['sections'];
$fields = $form_config['fields'];
+ $total = count($sections);
echo '<div class="container">';
+ if ($total > 1) {
+ echo '<div class="form-progress">';
+ jvbRenderProgressBar('<span class="step-text">Step <span class="current">1</span> of ' . $total . '</span>');
+ echo '</div>';
+ }
// Render navigation if multiple sections
if (count($sections) > 1) {
@@ -311,21 +319,24 @@
$active_class = $i === 1 ? ' active' : '';
$aria_selected = $i === 1 ? 'true' : 'false';
- echo '<button type="button" class="tab' . $active_class . '" data-tab="' . esc_attr($slug) . '" role="tab" aria-selected="' . $aria_selected . '">';
+ echo '<button type="button" class="tab' . $active_class . '" data-tab="' . esc_attr($slug) . '" data-step="'.$i.'" role="tab" aria-selected="' . $aria_selected . '">';
+ echo '<span class="step-number">' . $i . '</span>';
echo '<h2>' . esc_html($section['label'] ?? $section) . '</h2>';
echo '</button>';
$i++;
}
echo '</nav>';
}
+ echo jvbFormStatus();
// Render section content
$i = 0;
$total = count($sections);
foreach ($sections as $slug => $section) {
$active_class = $i === 0 ? ' active' : '';
+ $is_last = $i === ($total -1);
- echo '<section id="' . esc_attr($slug) . '" class="tab-content' . $active_class . '" data-tab="' . esc_attr($slug) . '" role="tabpanel">';
+ echo '<section id="' . esc_attr($slug) . '" class="tab-content' . $active_class . '" data-tab="' . esc_attr($slug) . '" data-step="'.($i + 1).'" role="tabpanel">';
if (is_array($section) && !empty($section['title'])) {
echo '<h2>' . esc_html($section['title']) . '</h2>';
@@ -344,14 +355,30 @@
$meta->render('form', $field_name, $field_config);
}
- if ($i === ($total - 1)){
- $submit_text = $form_config['submit'] ?? 'Submit';
- // Submit button
- echo '<div class="form-actions">';
- echo '<button type="submit">' . esc_html($submit_text) . '</button>';
- echo '</div>';
+ // Add step navigation buttons
+ echo '<div class="step-navigation row btw">';
+
+ if ($i > 0) {
+ echo '<button type="button" class="button secondary prev-step" data-action="prev-step">';
+ echo jvbIcon('caret-left');
+ echo '<span>Previous</span>';
+ echo '</button>';
+ } else {
+ echo '<div></div>'; // Spacer for flex layout
}
+ if ($is_last) {
+ $submit_text = $form_config['submit'] ?? 'Submit';
+ echo '<button type="submit" class="button primary">' . esc_html($submit_text) . '</button>';
+ } else {
+ echo '<button type="button" class="button primary next-step" data-action="next-step">';
+ echo '<span>Next Step</span>';
+ echo jvbIcon('caret-right');
+ echo '</button>';
+ }
+
+ echo '</div>'; // .step-navigation
+
echo '</section>';
$i++;
}
@@ -389,19 +416,6 @@
echo '<input type="hidden" name="timestamp" value="' . time() . '">';
echo '</form>';
-
- echo '<template class="formSummary">
- <section class="form-summary">
- <h2></h2>
- <div class="message"><p>You\'ll get an email with this information, too. If you need to make any changes, respond to that email.</p></div>
- <h3>Summary:</h3>';
-
- foreach($form_config['fields'] as $field=>$config) {
- $label = $config['summaryTitle'] ?? $config['label'];
-
- echo '<div id="'.$field.'"><h4>'.$label.'</h4><div></div></div>';
- }
- echo '</section></template>';
}
/**
@@ -423,11 +437,6 @@
];
}
- error_log('Form Localization: '.print_r([
- 'formTypes' => $form_types,
- 'availableForms' => $this->forms,
- 'nonce' => wp_create_nonce('jvbForm')
- ], true));
wp_localize_script('jvb-forms-editor-script', 'jvbFormsData', [
'formTypes' => $form_types,
'availableForms' => $this->forms,
--
Gitblit v1.10.0