title: Flash a error/success message on flask after .validate_on_submit
body: <p>Newbie to Flask and a very short time to learn to do something decent(College).
  I have a survey that I would like to use FLASH to flash the success and error messages(category), though I haven't been able to do so, I gave it a good research and I did get how it works, my code seems fine comparing to the examples I have found, but it is clearly not. If someone could please help me out, it would be much appreciated.</p>
  
  <p>This is the .py file</p>
  
  <pre><code>def index():
      form = Form()
      if form.validate_on_submit():
          flash(u'Thank you for your collaboration!', 'success')
          if not form.validate_on_submit():
              flash(u'Something went wrong!', 'error')
              return redirect(url_for('index'))
          return redirect(url_for('index'))
      #submission_successful = True #or False. you can determine this.
      return render_template('index1.html', form=form) #submission_successful=submission_successful)
  </code></pre>
  
  <p>the .html file</p>
  
  <pre><code>&lt;center&gt;
      &lt;form methods='POST'&gt;
          {{ form.csrf_token }}
          {{ form.hidden_tag() }}
          &lt;div style = font-size:18px; font-weight:bold; margin-left:200px; class="form-field"&gt; {{ form.Email.label }} &lt;br&gt; {{ form.Email }}  &lt;/div&gt; &lt;br&gt;
          &lt;div style = font-size:18px; font-weight:bold; margin-left:100px; class="form-field"&gt; {{ form.sex.label }} {{ form.sex }}   &lt;/div&gt; &lt;br&gt;
          &lt;div style = font-size:18px; font-weight:bold; margin-left:100px; class="form-field"&gt; {{ form.age.label }}  {{ form.age }}  &lt;/div&gt; &lt;br&gt;
          &lt;div style = font-size:18px; font-weight:bold; margin-left:100px; class="form-field"&gt; {{ form.Marital.label }}  {{ form.Marital }}  &lt;/div&gt; &lt;br&gt;
          &lt;div style = font-size:18px; font-weight:bold; margin-left:100px; class="form-field"&gt; {{ form.county.label}}  {{ form.county }}  &lt;/div&gt; &lt;br&gt;
          &lt;div style = font-size:18px; font-weight:bold; margin-left:100px; class="form-field"&gt; {{ form.Property.label }}  {{ form.Property }}  &lt;/div&gt; &lt;br&gt;
          &lt;div style = font-size:18px; font-weight:bold; margin-left:100px; class="form-field"&gt; {{ form.PropertyStatus.label }}  {{ form.PropertyStatus }}  &lt;/div&gt; &lt;br&gt;
          &lt;div style = font-size:18px; font-weight:bold; margin-left:100px; class="form-field"&gt; {{ form.Rooms.label }}  {{ form.Rooms }}  &lt;/div&gt; &lt;br&gt;
          &lt;div style = font-size:18px; font-weight:bold; margin-left:100px; class="form-field"&gt; {{ form.People.label}} &lt;br&gt; {{ form.People }} &lt;/div&gt; &lt;br&gt;
          &lt;div style = font-size:17px; font-weight:bold; margin-left:100px; class="form-field"&gt; {{ form.submit}}  &lt;/div&gt;
  
          {% with messages = get_flashed_messages(with_categories=true) %}
              {% if messages %}
                  {% for category, message in messages %}
                  {% if category == 'success'%}
                      &lt;div class='alert alert-success mb-3' role='alert' &gt;
                          {{ message }}
                      &lt;/div&gt;
                  {% endif %}
                  {% if category == 'error'%}
                      &lt;div class='alert alert-danger mb-3' role='alert' &gt;
                          {{ message }}
                      &lt;/div&gt;
                  {% endif %}
  
                  {% endfor %}
              {% endif %}
          {% endwith %}
  
  
      &lt;/center&gt;
      &lt;/form&gt;
  </code></pre>