*/ public function rules(): array { /** @var PreregistrationPage $page */ $page = $this->route('publicPage'); $page->loadMissing('blocks'); $emailRule = (new Email) ->rfcCompliant() ->preventSpoofing(); $phoneRules = ['nullable', 'string', 'max:255']; if ($page->isPhoneFieldEnabledForSubscribers()) { $phoneRules = [ Rule::requiredIf(fn (): bool => $page->isPhoneFieldRequiredForSubscribers()), 'nullable', 'string', 'max:32', new ValidPhoneNumber(app(PhoneNumberNormalizer::class)), ]; } return [ 'first_name' => ['required', 'string', 'max:255'], 'last_name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'max:255', $emailRule], 'phone' => $phoneRules, ]; } /** * @return array */ public function messages(): array { return [ 'email' => __('Please enter a valid email address.'), ]; } /** * @return array */ public function attributes(): array { return [ 'first_name' => __('First name'), 'last_name' => __('Last name'), 'email' => __('Email'), 'phone' => __('Phone'), ]; } protected function prepareForValidation(): void { $email = $this->input('email'); if (is_string($email)) { $this->merge([ 'email' => strtolower(trim($email)), ]); } /** @var PreregistrationPage $page */ $page = $this->route('publicPage'); if (! $page->isPhoneFieldEnabledForSubscribers()) { $this->merge(['phone' => null]); return; } $phone = $this->input('phone'); if ($phone === null || $phone === '') { $this->merge(['phone' => null]); return; } if (is_string($phone)) { $trimmed = trim($phone); $this->merge(['phone' => $trimmed === '' ? null : $trimmed]); } } }