Skip to content

Commit

Permalink
WPCIVIUX-162 Convert Self Serve Checksum form to a template part
Browse files Browse the repository at this point in the history
  • Loading branch information
agileware-iris committed Sep 27, 2024
1 parent 10262bf commit 6c81fd4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 29 deletions.
40 changes: 11 additions & 29 deletions shortcodes/self-serve-checksum/self-serve-checksum.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,43 +77,25 @@ public function shortcode_callback( $atts = [], $content = null, $tag = '' ) {
}
wp_enqueue_script('ss-cs-form', WP_CIVICRM_UX_PLUGIN_URL . WP_CIVICRM_UX_PLUGIN_NAME . '/public/js/self-serve-checksum.js', []);

ob_start();
$args = [
'form_submitted' => $form_submitted,
'turnstile' => $turnstile,
'turnstile_passed' => $turnstile_passed,
'form_text' => $formText,
'url' => $url,
'invalidMessage' => $invalidMessage,
];

ob_start();
?>
<div class='ss-cs-status-message status'>
<?php
echo $invalidMessage;
echo $args['invalid_message'];
$this->self_serve_checksum_handle_form_submission();
?>
</div>
<?php
if ( !$form_submitted || ( $form_submitted && !$turnstile_passed ) ) {
echo $formText; ?>
<form id="ss-cs-form" method="post" data-turnstilepassed="<?php echo $turnstile_passed ? 'true' : 'false'; ?>">
<label for="ss-cs-email">Your email:</label>
<input type="email" id="ss-cs-email" name="ss-cs-email" required>
<input type="hidden" name="ss-cs-title" value="<?php echo get_the_title(); ?>">
<input type="hidden" name="ss-cs-url" value="<?php echo $url; ?>">
<?php echo $turnstile; ?>
<button type="submit" name="ss-cs-submit" id="ss-cs-submit">Submit</button>
</form>
<?php
if ( !empty($turnstile) ) { ?>
<script>
let turnstileCompleted = false;

// This function will be called when Turnstile completes successfully
function onTurnstileComplete(token) {
turnstileCompleted = true;

let submitButton = document.getElementById('ss-cs-submit');
submitButton.disabled = false;
}
</script>
<?php } ?>
<?php } ?>

<?php
civicrm_ux_load_template_part( 'shortcode', 'self-serve-checksum', array_merge($args) );

return ob_get_clean();
}
Expand Down
33 changes: 33 additions & 0 deletions templates/shortcode/shortcode-self-serve-checksum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Default template for the [ux_self_serve_checksum] shortcode.
*
* To customise, copy this file into your theme and make changes as needed.
*/


if ( !$args['form_submitted'] || ( $args['form_submitted'] && !$args['turnstile_passed'] ) ) {
echo $args['form_text']; ?>
<form id="ss-cs-form" method="post" data-turnstilepassed="<?php echo $args['turnstile_passed'] ? 'true' : 'false'; ?>">
<label for="ss-cs-email">Your email:</label>
<input type="email" id="ss-cs-email" name="ss-cs-email" required>
<input type="hidden" name="ss-cs-title" value="<?php echo get_the_title(); ?>">
<input type="hidden" name="ss-cs-url" value="<?php echo $args['url']; ?>">
<?php echo $args['turnstile']; ?>
<button type="submit" name="ss-cs-submit" id="ss-cs-submit">Submit</button>
</form>
<?php
if ( !empty($args['turnstile']) ) { ?>
<script>
let turnstileCompleted = false;

// This function will be called when Turnstile completes successfully
function onTurnstileComplete(token) {
turnstileCompleted = true;

let submitButton = document.getElementById('ss-cs-submit');
submitButton.disabled = false;
}
</script>
<?php } ?>
<?php } ?>

0 comments on commit 6c81fd4

Please sign in to comment.