Make consent checkbox and form note configurable

Add independent admin controls for the consent checkbox and explanatory note. Keep both enabled by default so existing installations retain their current behavior.

Render the optional elements conditionally and require consent in server validation only when the checkbox is enabled. Bump the plugin and stable release version to 1.3.4, document the controls, and cover enabled/disabled rendering, validation, and invalid settings in the integration suite.

Validation: PHP syntax and NL/EN integration checks passed on Hephaestus, with mail intercepted during tests. Staged whitespace checks passed. No changes to antispam behavior or other website configurations.
This commit is contained in:
parkel committed 2026-11-09 23:41:55 +01:00
1 parent 0cad18c757
commit e1df255b0b
7 files changed
+25 -7

No files matched your search

+3 -2
View File
@@ -20,7 +20,7 @@ function hgcf_validate(array $source,$lang='nl') {
if($field==='date'&&$data[$key]!==''){$date=DateTimeImmutable::createFromFormat('!Y-m-d',$data[$key],wp_timezone());if(!$date||$date->format('Y-m-d')!==$data[$key]||$data[$key]<wp_date('Y-m-d'))$errors->add($key,hgcf_text('Kies vandaag of een datum in de toekomst.','Choose today or a future date.',$lang));}
if($field==='time'&&$data[$key]!==''&&(!preg_match('/^(?:[01][0-9]|2[0-3]):[0-5][0-9]$/',$data[$key])||$data[$key]<$flow['opening_time']||$data[$key]>$flow['closing_time']))$errors->add($key,sprintf(hgcf_text('Kies een tijd tussen %s en %s.','Choose a time between %s and %s.',$lang),$flow['opening_time'],$flow['closing_time']));
}
if(($source['consent']??'')!=='1')$errors->add('consent',hgcf_text('Geef toestemming om je gegevens voor een reactie te gebruiken.','Allow me to use your details to reply.',$lang));
if(hgcf_setting('show_consent')&&($source['consent']??'')!=='1')$errors->add('consent',hgcf_text('Geef toestemming om je gegevens voor een reactie te gebruiken.','Allow me to use your details to reply.',$lang));
if($errors->has_errors())return $errors;
foreach($data as $key=>$value)$data[$key]=$key==='message'?sanitize_textarea_field($value):sanitize_text_field($value);return $data;
}
@@ -62,7 +62,8 @@ function hgcf_render($atts=[]) {
<div class="form-fields"><?php if($has('date')): ?><label for="mlhc-date" data-hgcf-field="date"><span data-hgcf-label><?php echo esc_html($t('Voorkeursdatum','Preferred date')); ?></span><input id="mlhc-date" name="mlhc_preferred_date" type="date" min="<?php echo esc_attr(wp_date('Y-m-d')); ?>" value="<?php echo esc_attr($value('preferred_date')); ?>"></label><?php endif; ?><?php if($has('time')): ?><label for="mlhc-time" data-hgcf-field="time"><span data-hgcf-label><?php echo esc_html($t('Voorkeurstijd','Preferred time')); ?></span><input id="mlhc-time" name="mlhc_preferred_time" type="time" min="<?php echo esc_attr($flow['opening_time']); ?>" max="<?php echo esc_attr($flow['closing_time']); ?>" value="<?php echo esc_attr($value('preferred_time')); ?>"></label><?php endif; ?></div>
</fieldset><?php endif; ?><p class="form-note workflow-hint"><?php echo esc_html(hgcf_translated($flow['hint'],$lang)); ?></p>
<label for="mlhc-message"><span class="message-label"><?php echo esc_html(hgcf_translated($flow['message_label'],$lang)); ?></span><textarea id="mlhc-message" name="mlhc_message" rows="5" maxlength="5000"><?php echo esc_textarea($value('message')); ?></textarea></label>
<label class="consent"><input type="checkbox" name="mlhc_consent" value="1" required <?php checked($value('consent'),'1'); ?>><span><?php echo esc_html(hgcf_local_setting('consent',$lang)); ?></span></label><p class="form-note"><?php echo esc_html(hgcf_local_setting('note',$lang)); ?></p>
<?php if(hgcf_setting('show_consent')): ?><label class="consent"><input type="checkbox" name="mlhc_consent" value="1" required <?php checked($value('consent'),'1'); ?>><span><?php echo esc_html(hgcf_local_setting('consent',$lang)); ?></span></label><?php endif; ?>
<?php if(hgcf_setting('show_note')): ?><p class="form-note"><?php echo esc_html(hgcf_local_setting('note',$lang)); ?></p><?php endif; ?>
<?php if(hgcf_altcha_enabled()): ?><div class="hgcf-antispam"><altcha-widget name="mlhc_altcha" challenge="<?php echo esc_url(add_query_arg('page',get_queried_object_id(),rest_url('hg-contactform/v1/challenge'))); ?>" language="<?php echo esc_attr(substr($lang,0,2)); ?>" auto="onfocus" workers="2"></altcha-widget><noscript><p class="form-note"><?php echo esc_html($t('Schakel JavaScript in voor de antispamcontrole of gebruik een andere contactmogelijkheid.','Enable JavaScript for the spam protection check or use another contact option.')); ?></p></noscript></div><?php endif; ?>
<button type="submit" class="button"><?php echo esc_html($t('Verstuur bericht','Send message')); ?></button>
</form></section>