Skip to content

Commit 1736c4a

Browse files
authored
t509: fix: template_selection field validation maps to template_id rule key (#800)
1 parent 2d4054f commit 1736c4a

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

inc/checkout/class-checkout.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,17 @@ public function get_validation_rules() {
24212421
'products',
24222422
];
24232423

2424+
/*
2425+
* Maps checkout field IDs to their corresponding validation-rule
2426+
* keys when the two differ. For example the "template_selection"
2427+
* signup field submits its value as "template_id" in the POST data,
2428+
* so a `required` attribute on that field must target the
2429+
* "template_id" rule — not "template_selection".
2430+
*/
2431+
$field_to_rule_key = [
2432+
'template_selection' => 'template_id',
2433+
];
2434+
24242435
/**
24252436
* Add the additional required fields.
24262437
*/
@@ -2429,10 +2440,26 @@ public function get_validation_rules() {
24292440
* General required fields
24302441
*/
24312442
if (wu_get_isset($field, 'required') && wu_get_isset($field, 'id')) {
2432-
if (isset($validation_rules[ $field['id'] ])) {
2433-
$validation_rules[ $field['id'] ] .= '|required';
2443+
$rule_key = $field_to_rule_key[ $field['id'] ] ?? $field['id'];
2444+
2445+
if (isset($validation_rules[ $rule_key ])) {
2446+
$validation_rules[ $rule_key ] .= '|required';
24342447
} else {
2435-
$validation_rules[ $field['id'] ] = 'required';
2448+
$validation_rules[ $rule_key ] = 'required';
2449+
}
2450+
2451+
/*
2452+
* For template_id the `required` rule alone is not enough
2453+
* because Rakit considers integer 0 as "present". Add min:1
2454+
* so the checkout rejects template_id=0 when the form
2455+
* includes a required template selection field.
2456+
*
2457+
* Admin/network site creation does not go through checkout
2458+
* validation, so blank (no-template) sites can still be
2459+
* created from the network admin.
2460+
*/
2461+
if ('template_id' === $rule_key) {
2462+
$validation_rules[ $rule_key ] .= '|min:1';
24362463
}
24372464
}
24382465

@@ -2508,7 +2535,7 @@ public function validate($rules = null) {
25082535
[
25092536
'password_conf' => __('Password confirmation', 'ultimate-multisite'),
25102537
'email_address_confirmation' => __('Email confirmation', 'ultimate-multisite'),
2511-
'template_id' => __('Template ID', 'ultimate-multisite'),
2538+
'template_id' => __('Template Selection', 'ultimate-multisite'),
25122539
'valid_password' => __('Valid password', 'ultimate-multisite'),
25132540
'products' => __('Products', 'ultimate-multisite'),
25142541
'gateway' => __('Payment Gateway', 'ultimate-multisite'),

0 commit comments

Comments
 (0)