0

I've tried looking through the documentation and other posts on here, though I'm still having trouble.

views.py

@bp.route('/')
def index():
    return render_template("index.html")

@bp.route('/newSearch', methods=['GET', 'POST'])
def newSearch():
    form = NewSearchForm()
    if form.validate_on_submit():
        # DB code
        return redirect(url_for('newPage.html'))
    return render_template('newSearch.html', form=form)

Once the user enters a search query and clicks "submit" it should redirect to the results page. However, It's not validating the form correctly with my current form tag.

index.html

<form action="{{ url_for('newSearch') }}" enctype="multipart/form-data" method="post">    
    <input class="btn btn-primary" type="submit" value="Search"></input>
</form

The button lives in the index.html. It fails to redirect to newPage.html in the case above. What is missing that's causing it to fail validation? any help would be greatly appreciated!

resolute
  • 171
  • 2
  • 11
  • 2
    Your form knows why it failed to validate. After calling `form.validate_on_submit()`, you can inspect `form.errors` to see why validation failed. – noslenkwah Jan 26 '21 at 19:23
  • 1
    https://stackoverflow.com/questions/65757488/bootstrap-navbar-search-to-send-search-query-to-flask-view – cizario Jan 26 '21 at 19:47
  • If it is rendering `newSearch` page, then there must be an issue with form validation. – Iron Fist Jan 26 '21 at 19:53
  • @noslenkwah I did not know about printing form errors and now I see why, thank you! – resolute Jan 26 '21 at 20:49

0 Answers0