prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Typo in wagtailforms.forms.FormBuilder.formfields
  Line 86:
  
  ``` python
  raise Exception("Unrecognised field type: " + form.field_type)
  ```
  
  This raises `NameError: global name 'form' is not defined`
  
  Ordinarily the flow of things wouldn't run into this line, but I was caught out when badly naming a form field in the json fixtures.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `wagtail/wagtailforms/forms.py`
  Content:
  ```
  1 import django.forms
  2 from django.utils.datastructures import SortedDict
  3 
  4 
  5 class BaseForm(django.forms.Form):
  6     def __init__(self, *args, **kwargs):
  7         kwargs.setdefault('label_suffix', '')
  8         return super(BaseForm, self).__init__(*args, **kwargs)
  9 
  10 
  11 class FormBuilder(object):
  12     def __init__(self, fields):
  13         self.fields = fields
  14 
  15     def create_singleline_field(self, field, options):
  16         # TODO: This is a default value - it may need to be changed
  17         options['max_length'] = 255
  18         return django.forms.CharField(**options)
  19 
  20     def create_multiline_field(self, field, options):
  21         return django.forms.CharField(widget=django.forms.Textarea, **options)
  22 
  23     def create_date_field(self, field, options):
  24         return django.forms.DateField(**options)
  25 
  26     def create_datetime_field(self, field, options):
  27         return django.forms.DateTimeField(**options)
  28 
  29     def create_email_field(self, field, options):
  30         return django.forms.EmailField(**options)
  31 
  32     def create_url_field(self, field, options):
  33         return django.forms.URLField(**options)
  34 
  35     def create_number_field(self, field, options):
  36         return django.forms.DecimalField(**options)
  37 
  38     def create_dropdown_field(self, field, options):
  39         options['choices'] = map(
  40             lambda x: (x.strip(), x.strip()),
  41             field.choices.split(',')
  42         )
  43         return django.forms.ChoiceField(**options)
  44 
  45     def create_radio_field(self, field, options):
  46         options['choices'] = map(
  47             lambda x: (x.strip(), x.strip()),
  48             field.choices.split(',')
  49         )
  50         return django.forms.ChoiceField(widget=django.forms.RadioSelect, **options)
  51 
  52     def create_checkboxes_field(self, field, options):
  53         options['choices'] = [(x.strip(), x.strip()) for x in field.choices.split(',')]
  54         options['initial'] = [x.strip() for x in field.default_value.split(',')]
  55         return django.forms.MultipleChoiceField(
  56             widget=django.forms.CheckboxSelectMultiple, **options
  57         )
  58 
  59     def create_checkbox_field(self, field, options):
  60         return django.forms.BooleanField(**options)
  61 
  62     FIELD_TYPES = {
  63         'singleline': create_singleline_field,
  64         'multiline': create_multiline_field,
  65         'date': create_date_field,
  66         'datetime': create_datetime_field,
  67         'email': create_email_field,
  68         'url': create_url_field,
  69         'number': create_number_field,
  70         'dropdown': create_dropdown_field,
  71         'radio': create_radio_field,
  72         'checkboxes': create_checkboxes_field,
  73         'checkbox': create_checkbox_field,
  74     }
  75 
  76     @property
  77     def formfields(self):
  78         formfields = SortedDict()
  79 
  80         for field in self.fields:
  81             options = self.get_field_options(field)
  82 
  83             if field.field_type in self.FIELD_TYPES:
  84                 formfields[field.clean_name] = self.FIELD_TYPES[field.field_type](self, field, options)
  85             else:
  86                 raise Exception("Unrecognised field type: " + form.field_type)
  87 
  88         return formfields
  89 
  90     def get_field_options(self, field):
  91         options = {}
  92         options['label'] = field.label
  93         options['help_text'] = field.help_text
  94         options['required'] = field.required
  95         options['initial'] = field.default_value
  96         return options
  97 
  98     def get_form_class(self):
  99         return type('WagtailForm', (BaseForm,), self.formfields)
  100 
  101 
  102 class SelectDateForm(django.forms.Form):
  103     date_from = django.forms.DateTimeField(
  104         required=False,
  105         widget=django.forms.DateInput(attrs={'placeholder': 'Date from'})
  106     )
  107     date_to = django.forms.DateTimeField(
  108         required=False,
  109         widget=django.forms.DateInput(attrs={'placeholder': 'Date to'})
  110     )
  111
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/wagtail/wagtailforms/forms.py b/wagtail/wagtailforms/forms.py
  --- a/wagtail/wagtailforms/forms.py
  +++ b/wagtail/wagtailforms/forms.py
  @@ -83,7 +83,7 @@
               if field.field_type in self.FIELD_TYPES:
                   formfields[field.clean_name] = self.FIELD_TYPES[field.field_type](self, field, options)
               else:
  -                raise Exception("Unrecognised field type: " + form.field_type)
  +                raise Exception("Unrecognised field type: " + field.field_type)
   
           return formfields
  
verification_info: {"golden_diff": "diff --git a/wagtail/wagtailforms/forms.py b/wagtail/wagtailforms/forms.py\n--- a/wagtail/wagtailforms/forms.py\n+++ b/wagtail/wagtailforms/forms.py\n@@ -83,7 +83,7 @@\n             if field.field_type in self.FIELD_TYPES:\n                 formfields[field.clean_name] = self.FIELD_TYPES[field.field_type](self, field, options)\n             else:\n-                raise Exception(\"Unrecognised field type: \" + form.field_type)\n+                raise Exception(\"Unrecognised field type: \" + field.field_type)\n \n         return formfields\n", "issue": "Typo in wagtailforms.forms.FormBuilder.formfields\nLine 86:\n\n``` python\nraise Exception(\"Unrecognised field type: \" + form.field_type)\n```\n\nThis raises `NameError: global name 'form' is not defined`\n\nOrdinarily the flow of things wouldn't run into this line, but I was caught out when badly naming a form field in the json fixtures.\n\n", "before_files": [{"content": "import django.forms\nfrom django.utils.datastructures import SortedDict\n\n\nclass BaseForm(django.forms.Form):\n    def __init__(self, *args, **kwargs):\n        kwargs.setdefault('label_suffix', '')\n        return super(BaseForm, self).__init__(*args, **kwargs)\n\n\nclass FormBuilder(object):\n    def __init__(self, fields):\n        self.fields = fields\n\n    def create_singleline_field(self, field, options):\n        # TODO: This is a default value - it may need to be changed\n        options['max_length'] = 255\n        return django.forms.CharField(**options)\n\n    def create_multiline_field(self, field, options):\n        return django.forms.CharField(widget=django.forms.Textarea, **options)\n\n    def create_date_field(self, field, options):\n        return django.forms.DateField(**options)\n\n    def create_datetime_field(self, field, options):\n        return django.forms.DateTimeField(**options)\n\n    def create_email_field(self, field, options):\n        return django.forms.EmailField(**options)\n\n    def create_url_field(self, field, options):\n        return django.forms.URLField(**options)\n\n    def create_number_field(self, field, options):\n        return django.forms.DecimalField(**options)\n\n    def create_dropdown_field(self, field, options):\n        options['choices'] = map(\n            lambda x: (x.strip(), x.strip()),\n            field.choices.split(',')\n        )\n        return django.forms.ChoiceField(**options)\n\n    def create_radio_field(self, field, options):\n        options['choices'] = map(\n            lambda x: (x.strip(), x.strip()),\n            field.choices.split(',')\n        )\n        return django.forms.ChoiceField(widget=django.forms.RadioSelect, **options)\n\n    def create_checkboxes_field(self, field, options):\n        options['choices'] = [(x.strip(), x.strip()) for x in field.choices.split(',')]\n        options['initial'] = [x.strip() for x in field.default_value.split(',')]\n        return django.forms.MultipleChoiceField(\n            widget=django.forms.CheckboxSelectMultiple, **options\n        )\n\n    def create_checkbox_field(self, field, options):\n        return django.forms.BooleanField(**options)\n\n    FIELD_TYPES = {\n        'singleline': create_singleline_field,\n        'multiline': create_multiline_field,\n        'date': create_date_field,\n        'datetime': create_datetime_field,\n        'email': create_email_field,\n        'url': create_url_field,\n        'number': create_number_field,\n        'dropdown': create_dropdown_field,\n        'radio': create_radio_field,\n        'checkboxes': create_checkboxes_field,\n        'checkbox': create_checkbox_field,\n    }\n\n    @property\n    def formfields(self):\n        formfields = SortedDict()\n\n        for field in self.fields:\n            options = self.get_field_options(field)\n\n            if field.field_type in self.FIELD_TYPES:\n                formfields[field.clean_name] = self.FIELD_TYPES[field.field_type](self, field, options)\n            else:\n                raise Exception(\"Unrecognised field type: \" + form.field_type)\n\n        return formfields\n\n    def get_field_options(self, field):\n        options = {}\n        options['label'] = field.label\n        options['help_text'] = field.help_text\n        options['required'] = field.required\n        options['initial'] = field.default_value\n        return options\n\n    def get_form_class(self):\n        return type('WagtailForm', (BaseForm,), self.formfields)\n\n\nclass SelectDateForm(django.forms.Form):\n    date_from = django.forms.DateTimeField(\n        required=False,\n        widget=django.forms.DateInput(attrs={'placeholder': 'Date from'})\n    )\n    date_to = django.forms.DateTimeField(\n        required=False,\n        widget=django.forms.DateInput(attrs={'placeholder': 'Date to'})\n    )\n", "path": "wagtail/wagtailforms/forms.py"}], "after_files": [{"content": "import django.forms\nfrom django.utils.datastructures import SortedDict\n\n\nclass BaseForm(django.forms.Form):\n    def __init__(self, *args, **kwargs):\n        kwargs.setdefault('label_suffix', '')\n        return super(BaseForm, self).__init__(*args, **kwargs)\n\n\nclass FormBuilder(object):\n    def __init__(self, fields):\n        self.fields = fields\n\n    def create_singleline_field(self, field, options):\n        # TODO: This is a default value - it may need to be changed\n        options['max_length'] = 255\n        return django.forms.CharField(**options)\n\n    def create_multiline_field(self, field, options):\n        return django.forms.CharField(widget=django.forms.Textarea, **options)\n\n    def create_date_field(self, field, options):\n        return django.forms.DateField(**options)\n\n    def create_datetime_field(self, field, options):\n        return django.forms.DateTimeField(**options)\n\n    def create_email_field(self, field, options):\n        return django.forms.EmailField(**options)\n\n    def create_url_field(self, field, options):\n        return django.forms.URLField(**options)\n\n    def create_number_field(self, field, options):\n        return django.forms.DecimalField(**options)\n\n    def create_dropdown_field(self, field, options):\n        options['choices'] = map(\n            lambda x: (x.strip(), x.strip()),\n            field.choices.split(',')\n        )\n        return django.forms.ChoiceField(**options)\n\n    def create_radio_field(self, field, options):\n        options['choices'] = map(\n            lambda x: (x.strip(), x.strip()),\n            field.choices.split(',')\n        )\n        return django.forms.ChoiceField(widget=django.forms.RadioSelect, **options)\n\n    def create_checkboxes_field(self, field, options):\n        options['choices'] = [(x.strip(), x.strip()) for x in field.choices.split(',')]\n        options['initial'] = [x.strip() for x in field.default_value.split(',')]\n        return django.forms.MultipleChoiceField(\n            widget=django.forms.CheckboxSelectMultiple, **options\n        )\n\n    def create_checkbox_field(self, field, options):\n        return django.forms.BooleanField(**options)\n\n    FIELD_TYPES = {\n        'singleline': create_singleline_field,\n        'multiline': create_multiline_field,\n        'date': create_date_field,\n        'datetime': create_datetime_field,\n        'email': create_email_field,\n        'url': create_url_field,\n        'number': create_number_field,\n        'dropdown': create_dropdown_field,\n        'radio': create_radio_field,\n        'checkboxes': create_checkboxes_field,\n        'checkbox': create_checkbox_field,\n    }\n\n    @property\n    def formfields(self):\n        formfields = SortedDict()\n\n        for field in self.fields:\n            options = self.get_field_options(field)\n\n            if field.field_type in self.FIELD_TYPES:\n                formfields[field.clean_name] = self.FIELD_TYPES[field.field_type](self, field, options)\n            else:\n                raise Exception(\"Unrecognised field type: \" + field.field_type)\n\n        return formfields\n\n    def get_field_options(self, field):\n        options = {}\n        options['label'] = field.label\n        options['help_text'] = field.help_text\n        options['required'] = field.required\n        options['initial'] = field.default_value\n        return options\n\n    def get_form_class(self):\n        return type('WagtailForm', (BaseForm,), self.formfields)\n\n\nclass SelectDateForm(django.forms.Form):\n    date_from = django.forms.DateTimeField(\n        required=False,\n        widget=django.forms.DateInput(attrs={'placeholder': 'Date from'})\n    )\n    date_to = django.forms.DateTimeField(\n        required=False,\n        widget=django.forms.DateInput(attrs={'placeholder': 'Date to'})\n    )\n", "path": "wagtail/wagtailforms/forms.py"}]}