I have a flask project that basically has 2 Form Classes that act as a subform in the third Form Class. I use the 2 subforms with the FormField field. The problem is that when I submit the form, I get csrf_token errors for the two subforms. If I use the csrf=false property in the subforms I don't get this, but does this now mean I am open to CSRF attacks?
class AddressForm(FlaskForm):
address = StringField(label='Address', validators=[DataRequired()])
address2 = StringField(label='Address 2', validators=[Optional()])
city = StringField(label='City', validators=[DataRequired()])
county = SelectField(label='County', validators=[DataRequired()], choices=[], coerce=int)
class Meta:
csrf = False
class NameForm(FlaskForm):
first_name = StringField(label='First Name', validators=[DataRequired(), Length(min=2)] )
last_name = StringField(label='Last Name', validators=[DataRequired(), Length(min=2)] )
class Meta:
csrf = False
class OrderForm(FlaskForm):
# Customer Details
customer_name = FormField(NameForm, separator='_')
customer_email = EmailField(label='Email', validators=[DataRequired(), Email()])
customer_mobile_phone = StringField(label='Mobile Phone Number', validators=[DataRequired()])
customer_alternative_phone = StringField(label='Alternative Phone Number', validators=[Optional()])
# Delivery Details
delivery_address = FormField(AddressForm, separator='_')
area = SelectField(label='Area', validators=[DataRequired()], coerce=int)
I have included the {{ form.hidden_tag() }} in the form and also have a SECRET_KEY configured.