'Create a new form field (in most cases) or update an existing FormField
instance.
:param attributes: The tag attributes for the newly found form input
:return: The newly created / updated form field'

def form_field_factory(self, attributes):

    input_name = get_value_by_key(attributes, 'name', 'id')
    if (input_name is None):
        return (False, None)
    snf = self.meta.get(input_name, [])
    input_type = (get_value_by_key(attributes, 'type') or INPUT_TYPE_TEXT)
    input_type = input_type.lower()
    input_value = (get_value_by_key(attributes, 'value') or '')
    autocomplete = (get_value_by_key(attributes, 'autocomplete') or '')
    autocomplete = (False if (autocomplete.lower() == 'off') else True)
    should_add_new = True
    if (input_type == INPUT_TYPE_SELECT):
        input_values = (get_value_by_key(attributes, 'values') or [])
        form_field = SelectFormField(input_name, input_values)
    elif (input_type == INPUT_TYPE_RADIO):
        match_fields = [ff for ff in snf if (ff.input_type is INPUT_TYPE_RADIO)]
        if match_fields:
            form_field = match_fields[(-1)]
            form_field.values.append(input_value)
            should_add_new = False
        else:
            form_field = RadioFormField(input_name, [input_value])
    elif (input_type == INPUT_TYPE_CHECKBOX):
        match_fields = [ff for ff in snf if (ff.input_type is INPUT_TYPE_CHECKBOX)]
        if match_fields:
            form_field = match_fields[(-1)]
            form_field.values.append(input_value)
            should_add_new = False
        else:
            form_field = CheckboxFormField(input_name, [input_value])
    elif (input_type == INPUT_TYPE_FILE):
        file_name = get_value_by_key(attributes, 'filename')
        form_field = FileFormField(input_name, value=input_value, file_name=file_name)
    else:
        form_field = GenericFormField(input_type, input_name, input_value, autocomplete=autocomplete)
    return (should_add_new, form_field)
