title: Flask wtf form not validating custom validators
body: <p>So i have a login form and signup form on a single html page. I have custom validators for signup form that are not working.
  The <em><strong>routes.py</strong></em> looks like this</p>
  <pre class="lang-py prettyprint-override"><code>@app.route(&quot;/&quot;, methods=['GET', 'POST'])
  def home():
      login_form = LoginForm(request.form, prefix=&quot;login-form&quot;)
      regis_form = RegistrationForm(request.form, prefix=&quot;register-form&quot;)
      return render_template('home.html', login_form=login_form, regis_form=regis_form)
  
  
  @app.route(&quot;/register&quot;, methods=['POST'])
  def register():
      regis_form  = RegistrationForm(request.form, prefix='register-form')
      if regis_form.validate_on_submit():
          hashed_password = bcrypt.generate_password_hash(regis_form.password_regis.data).decode('utf-8')
          user = User(username=regis_form.username_regis.data, email=regis_form.email_regis.data, password=hashed_password)
          db.session.add(user)
          db.session.commit()
          flash('Your account has been created! You are now able to log in', 'success')
          return redirect(url_for('home'))
      return redirect(url_for('home'))
  
  @app.route(&quot;/login&quot;, methods=['POST'])
  def login():
      login_form = LoginForm(request.form, prefix='login-form')
      if login_form.validate_on_submit():
          user = User.query.filter_by(email=login_form.email_login.data).first()
          if user and bcrypt.check_password_hash(user.password, login_form.password_login.data):
              login_user(user, remember=login_form.remember.data)
              next_page = request.args.get('next')
              return redirect(next_page) if next_page else redirect(url_for('home'))
          else:
              flash('Login Unsuccessful. Please check email and password', 'danger')
      return redirect(url_for('home'))
  </code></pre>
  <p><em><strong>forms.py</strong></em></p>
  <pre class="lang-py prettyprint-override"><code>class RegistrationForm(FlaskForm):
      username_regis = StringField('Username',
                             validators=[DataRequired(), Length(min=5, max=20)])
      email_regis = EmailField('Email',
                          validators=[DataRequired(), Email()])
      password_regis = PasswordField('Password', validators=[DataRequired()])
      submit_regis = SubmitField('Sign Up')
  
      def validate_username_regis(self, username_regis):
          user = User.query.filter_by(username=username_regis.data).first()
          if user:
              raise ValidationError('That username is taken. Please choose a different one.')
  
      def validate_email_regis(self, email_regis):
          user = User.query.filter_by(email=email_regis.data).first()
          if user:
              raise ValidationError('That email is taken. Please choose a different one.')
  
  
  
  class LoginForm(FlaskForm):
      email_login = EmailField('Email',
                          validators=[DataRequired(), Email()])
      password_login = PasswordField('Password', validators=[DataRequired()])
      remember = BooleanField('Remember Me')
      submit_login = SubmitField('Login')
  </code></pre>
  <p><em><strong>home.html</strong></em></p>
  <pre class="lang-html prettyprint-override"><code>&lt;div&gt;
    &lt;form method=&quot;POST&quot; action=&quot;{{ url_for('login') }}&quot;&gt;
        {{ login_form.hidden_tag() }}
        &lt;fieldset class=&quot;form-group&quot;&gt;
            &lt;div class=&quot;form-group&quot;&gt;
                {% if login_form.email_login.errors %}
                    {{ login_form.email_login(class=&quot;form-control is-invalid&quot;) }}
                    &lt;div class=&quot;invalid-feedback&quot;&gt;
                        {% for error in login_form.email_login.errors %}
                            &lt;span&gt;{{ error }}&lt;/span&gt;
                        {% endfor %}
                    &lt;/div&gt;
                {% else %}
                    {{ login_form.email_login(class=&quot;form-control mb-2&quot;, placeholder=&quot;Email&quot;) }}
                {% endif %}
            &lt;/div&gt;
            &lt;div class=&quot;form-group&quot;&gt;
                {% if login_form.password_login.errors %}
                    {{ login_form.password_login(class=&quot;form-control is-invalid&quot;) }}
                    &lt;div class=&quot;invalid-feedback&quot;&gt;
                        {% for error in login_form.password_login.errors %}
                            &lt;span&gt;{{ error }}&lt;/span&gt;
                        {% endfor %}
                    &lt;/div&gt;
                {% else %}
                    {{ login_form.password_login(class=&quot;form-control mb-2&quot;, placeholder=&quot;Password&quot;) }}
                {% endif %}
            &lt;/div&gt;
        &lt;/fieldset&gt;
        &lt;div class=&quot;form-group&quot;&gt;
            {{ login_form.submit_login(class=&quot;btn btn-danger&quot;) }}
        &lt;/div&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  &lt;div class=&quot;&quot; id=&quot;regis&quot;&gt;
    &lt;form method=&quot;POST&quot; action=&quot;{{ url_for('register') }}&quot;&gt;
        {{ regis_form.hidden_tag() }}
        &lt;fieldset class=&quot;form-group&quot;&gt;
            &lt;div class=&quot;form-group&quot;&gt;
                {% if regis_form.username_regis.errors %}
                    {{ regis_form.username_regis(class=&quot;form-control form-control-md is-invalid&quot;) }}
                    &lt;div class=&quot;invalid-feedback&quot;&gt;
                        {% for error in regis_form.username_regis.errors %}
                            &lt;span&gt;{{ error }}&lt;/span&gt;
                        {% endfor %}
                    &lt;/div&gt;
                {% else %}
                    {{ regis_form.username_regis(class=&quot;form-control form-control-md mb-2&quot;, placeholder=&quot;Username&quot;) }}
                {% endif %}
            &lt;/div&gt;
            &lt;div class=&quot;form-group&quot;&gt;
                {% if regis_form.email_regis.errors %}
                    {{ regis_form.email_regis(class=&quot;form-control form-control-md is-invalid&quot;) }}
                    &lt;div class=&quot;invalid-feedback&quot;&gt;
                        {% for error in regis_form.email_regis.errors %}
                            &lt;span&gt;{{ error }}&lt;/span&gt;
                        {% endfor %}
                    &lt;/div&gt;
                {% else %}
                    {{ regis_form.email_regis(class=&quot;form-control form-control-md mb-2&quot;, placeholder=&quot;Email&quot;) }}
                {% endif %}
            &lt;/div&gt;
            &lt;div class=&quot;form-group&quot;&gt;
                {% if regis_form.password_regis.errors %}
                    {{ regis_form.password_regis(class=&quot;form-control form-control-md is-invalid&quot;) }}
                    &lt;div class=&quot;invalid-feedback&quot;&gt;
                        {% for error in regis_form.password_regis.errors %}
                            &lt;span&gt;{{ error }}&lt;/span&gt;
                        {% endfor %}
                    &lt;/div&gt;
                {% else %}
                    {{ regis_form.password_regis(class=&quot;form-control form-control-md mb-2&quot;, placeholder=&quot;Password&quot;) }}
                {% endif %}
            &lt;/div&gt;
        &lt;/fieldset&gt;
        &lt;div class=&quot;form-group&quot;&gt;
            {{ regis_form.submit_regis(class=&quot;btn btn-danger&quot;) }}
        &lt;/div&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Previously I had both forms on the same <em>home</em> route, custom validators were working but if i submitted <em>register</em> form with errors purposefully, then the login form also shows error like <em>input required</em>. So to fix that I did this, but now signup form is not validating custom validators</p>