class MarketAccessSummaryForm(forms.Form): contact_by_email = forms.BooleanField( label='I would like to receive additional information by email', required=False, ) contact_by_phone = forms.BooleanField( label='I would like to receive additional information by telephone', required=False, )
class CheckboxForm(PrefixIdMixin, forms.Form): checkbox1 = forms.BooleanField( label='Q1: Label text', help_text=( 'This is some help text. This help text is very long so ' 'you can see how it wraps next to the form elements. Very very ' 'long boring text that doesn\'t say anything. Why are you ' 'reading this?'), widget=forms.CheckboxWithInlineLabel(attrs={'id': 'checkbox-one'})) checkbox2 = forms.BooleanField( label='Q2: Label text with no help text', widget=forms.CheckboxWithInlineLabel(attrs={'id': 'checkbox-two'})) checkbox3 = forms.BooleanField( label='Q3: Example of small checkbox', widget=forms.CheckboxWithInlineLabel(attrs={'id': 'checkbox-three'}), container_css_classes='checkbox-small', )
class ContactUsHelpForm(GovNotifyEmailActionMixin, forms.Form): comment = forms.CharField( label='Please give us as much detail as you can', widget=Textarea, ) given_name = forms.CharField(label='First name') family_name = forms.CharField(label='Last name') email = forms.EmailField() captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3()) terms_agreed = forms.BooleanField(label=TERMS_LABEL)
class DemoFormErrors(PrefixIdMixin, forms.Form): error_summary_heading = 'There was a problem submitting the form' text_field1 = forms.CharField(label='Simple text field', help_text='Some help text', required=True) checkbox1 = forms.BooleanField( label='Label text', required=True, help_text=('Some help text.'), widget=forms.CheckboxWithInlineLabel(attrs={'id': 'checkbox-one'})) multiple_choice = forms.MultipleChoiceField( label='Multiple choice checkboxes', required=True, help_text='Some help text.', widget=forms.CheckboxSelectInlineLabelMultiple( attrs={'id': 'checkbox-multiple'}, use_nice_ids=True, ), choices=( ('red', 'Red'), ('green', 'Green'), ('blue', 'Blue'), ), ) radio = forms.ChoiceField( label='Radio select', required=True, label_suffix='', help_text='Some help text.', widget=forms.RadioSelect(use_nice_ids=True, attrs={'id': 'radio-one'}), choices=( (True, 'Yes'), (False, 'No'), )) def clean(self, *args, **kwargs): self.add_error( field=None, error=['Some non-field error', 'Some other non-field error']) super().clean(*args, **kwargs)
class BaseShortForm(forms.Form): comment = forms.CharField( label='Please give us as much detail as you can', widget=Textarea, ) given_name = forms.CharField(label='First name') family_name = forms.CharField(label='Last name') email = forms.EmailField() company_type = forms.ChoiceField( label='Company type', label_suffix='', widget=forms.RadioSelect(), choices=COMPANY_TYPE_CHOICES, ) company_type_other = forms.ChoiceField( label='Type of organisation', label_suffix='', choices=(('', 'Please select'), ) + COMPANY_TYPE_OTHER_CHOICES, required=False, ) organisation_name = forms.CharField() postcode = forms.CharField() captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3()) terms_agreed = forms.BooleanField(label=TERMS_LABEL)
def build_checkbox(label): return forms.BooleanField( label=label, required=False, widget=forms.CheckboxWithInlineLabel(attrs={'disabled': True}) )
class ExportSupportForm(GovNotifyEmailActionMixin, forms.Form): EMPLOYEES_NUMBER_CHOICES = ( ('1-9', '1 to 9'), ('10-49', '10 to 49'), ('50-249', '50 to 249'), ('250-499', '250 to 499'), ('500plus', 'More than 500'), ) first_name = forms.CharField( label='First name', min_length=2, max_length=50, error_messages={'required': 'Enter your first name'}) last_name = forms.CharField( label='Last name', min_length=2, max_length=50, error_messages={'required': 'Enter your last name'}) email = forms.EmailField( label='Email address', error_messages={ 'required': 'Enter an email address in the correct format, like [email protected]', 'invalid': 'Enter an email address in the correct format, like [email protected]', }, ) phone_number = forms.CharField( label='UK telephone number', min_length=8, help_text='This can be a landline or mobile number', error_messages={ 'max_length': 'Figures only, maximum 16 characters, minimum 8 characters excluding spaces', 'min_length': 'Figures only, maximum 16 characters, minimum 8 characters excluding spaces', 'required': 'Enter a UK phone number', 'invalid': 'Please enter a UK phone number', }, ) job_title = forms.CharField( label='Job title', max_length=50, error_messages={ 'required': 'Enter your job title', }, ) company_name = forms.CharField( label='Business name', max_length=50, error_messages={ 'required': 'Enter your business name', }, ) company_postcode = forms.CharField( label='Business postcode', max_length=50, error_messages={ 'required': 'Enter your business postcode', 'invalid': 'Please enter a UK postcode' }, validators=[is_valid_uk_postcode], ) annual_turnover = forms.ChoiceField( label='Annual turnover', help_text= ('This information will help us tailor our response and advice on the services we can provide.' ), choices=( ('Less than £500K', 'Less than £500K'), ('£500K to £2M', '£500K to £2M'), ('£2M to £5M', '£2M to £5M'), ('£5M to £10M', '£5M to £10M'), ('£10M to £50M', '£10M to £50M'), ('£50M or higher', '£50M or higher'), ), widget=forms.RadioSelect, required=False, ) employees_number = forms.ChoiceField( label='Number of employees', choices=EMPLOYEES_NUMBER_CHOICES, widget=forms.RadioSelect, error_messages={ 'required': 'Choose a number', }, ) currently_export = forms.ChoiceField( label='Do you currently export?', choices=(('yes', 'Yes'), ('no', 'No')), widget=forms.RadioSelect, error_messages={'required': 'Please answer this question'}, ) terms_agreed = forms.BooleanField( label=TERMS_LABEL, error_messages={ 'required': 'You must agree to the terms and conditions before registering', }, ) comment = forms.CharField( label='Please give us as much detail as you can on your enquiry', widget=Textarea, ) captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3()) def clean_phone_number(self): phone_number = self.cleaned_data['phone_number'].replace(' ', '') if not PHONE_NUMBER_REGEX.match(phone_number): raise ValidationError('Please enter a UK phone number') return phone_number def clean_company_postcode(self): return self.cleaned_data['company_postcode'].replace(' ', '').upper() @property def serialized_data(self): data = super().serialized_data employees_number_mapping = dict(self.EMPLOYEES_NUMBER_CHOICES) data['employees_number_label'] = employees_number_mapping.get( data['employees_number']) return data
class UKEFContactForm(GovNotifyEmailActionMixin, forms.Form): full_name = forms.CharField( label=_('Full name'), min_length=2, max_length=50, error_messages={ 'required': _('Enter your full name'), }, ) job_title = forms.CharField( label=_('Job title'), max_length=50, error_messages={ 'required': _('Enter your job title'), }, ) email = forms.EmailField( label=_('Business email address'), error_messages={ 'required': _('Enter an email address in the correct format, like [email protected]' ), 'invalid': _('Enter an email address in the correct format, like [email protected]' ), }, ) business_name = forms.CharField( label=_('Business name'), max_length=50, error_messages={ 'required': _('Enter your business name'), }, ) business_website = forms.CharField( label=_('Business website'), max_length=255, error_messages={ 'required': _('Enter a website address in the correct format, like https://www.example.com or www.company.com' ), 'invalid': _('Enter a website address in the correct format, like https://www.example.com or www.company.com' ), }, required=False, ) country = forms.ChoiceField( label=_('Which country are you based in?'), widget=Select(), choices=COUNTRIES, ) like_to_discuss = forms.ChoiceField( label=_( 'Do you have a specific project or proposal you’d like to discuss?' ), choices=( ('no', 'No'), ('yes', 'Yes'), ), widget=forms.RadioSelect, error_messages={'required': _('Please answer this question')}, ) like_to_discuss_other = forms.ChoiceField( label=_('Which country is the project located in?'), widget=Select(), choices=COUNTRIES, required=False, ) how_can_we_help = forms.CharField( label=_('How can we help?'), help_text=_( 'Please tell us briefly what type of support you’re looking for'), widget=Textarea, ) terms_agreed = forms.BooleanField( label=TERMS_LABEL, error_messages={ 'required': _('You must agree to the terms and conditions' ' before registering'), }, ) captcha = ReCaptchaField( label='', label_suffix='', widget=ReCaptchaV3(), ) @property def serialized_data(self): data = super().serialized_data countries_mapping = dict(COUNTRY_CHOICES) country_label = countries_mapping.get(data['country']) data['country_label'] = country_label data['like_to_discuss_country'] = '' if data.get('like_to_discuss') == 'yes': data['like_to_discuss_country'] = countries_mapping.get( data['like_to_discuss_other']) return data