My input is pretty weirdly formatted, but according to spec:

The user must enter the identifier in 4 fields (!), Where id is the form 460 000 005 001, where 46 is the country code, and the right part is the application identifier. Now I want to add confirmation to this field, but I cannot do this using wtforms. Here is my form class:
class RegisterWTForm(Form): soc_sec = TextField(_('Soc security number'), [validators.Regexp('^[0-9]+$', message=_('This is not a social security number, please see the example and try again' )), validators.Required(message=_('Social security number is required')), unique_soc_sec], widget=MyTextInput()) email = TextField(_('Email'), [validators.Required(message=_('Email is required' )), validators.Email(message=_('Your email is invalid' ))], widget=MyTextInput()) def validate_soc_sec(form, field): if len(field.data) != 10: raise ValidationError(_('Soc sec must be 10 characters' )) def validate_email(form, field): if len(field.data) > 60: raise ValidationError(_('Email must be less than 60 characters' ))
And here is how I now use variables, they are not part of WTForm, but are regular http post parameters:
def post(self): Log1 = self.request.POST.get('Log1') Log2 = self.request.POST.get('Log2') Log3 = self.request.POST.get('Log3') Log4 = self.request.POST.get('Log4') form = RegisterWTForm(self.request.params) if form.validate(): logging.info('validated successfully') else: logging.info('form did not validate') self.render_jinja('register.html', form=form, Log1=Log1, Log2=Log2, Log3=Log3, Log4=Log4 ) return '' email = self.request.POST.get('email') sponsor_id = '%s%s%s' % (Log2, Log3, Log4) if sponsor_id: user = User.get_by_id(long(sponsor_id)) else: return 'Sponsor with sponsor id %s does not exist' % sponsor_id if not user: return 'Sponsor with sponsor id %s does not exist' % sponsor_id
Is there a way to add my 4 variables as a single variable to my WTForm and add validation there, or should I do my own check for these fields? For my other fields, I made them with a red border and red text, if the field does not pass the test, and I would like to do the same here, but there will be a lot of logic in the presentation layer, if I cannot do it with the form class and add the code into the template. Can you suggest what to do?
thanks
Update
I can create a FormField that combines the fields, but they do not display correctly, and I do not need all 4 checks. Maybe you can tell me more how to do it the way I want?
class SponsorWTForm(Form): log1 = IntegerField('log1', [validators.required()]) log2 = IntegerField('log2', [validators.required()]) log3 = IntegerField('log3', [validators.required()]) log4 = IntegerField('log4', [validators.required()]) class RegisterWTForm(Form): sponsor_id = FormField(SponsorWTForm)
...
