form in bootstrap modal

203 views
Skip to first unread message

R U

unread,
Sep 14, 2017, 2:16:44 PM9/14/17
to web...@googlegroups.com
I have embedded a form inside of a bootstrap modal.  If the form is filled in correctly it redirects.  If there are errors the modal closes and the main page goes back to how it first looked.  Only when I click on the "Sign up Here" button does it reveal that there were errors and what the errors are.  Any idea on how to keep the modal open if there are errors

Thanks

view:::::::

 <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Sign up Here</button>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Here is all the informaiton we will need from you.</h4>
          <h4 class="modal-title">
              some more info about this modal
          </h4>
      </div>
      <div class="modal-body">
        <p>{{=index}}</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

controller::::::

def index():
  
    form=SQLFORM(userdb.person)
    if form.process(keepvalues=True).accepted:
        response.flash = "Thank you for filling out the form."
        redirect(URL('thank_you'))
    elif form.errors:
        response.flash = "form has errors"
    else:
        response.flash = "please fill out the form"
    return dict(index=form)

Leonel Câmara

unread,
Sep 20, 2017, 6:23:11 AM9/20/17
to web2py-users
One way to do it is to load the form in the modal's body using $.web2py.component when the user triggers the action that opens it, then you can use response.js to close the modal if the form is submitted without errors.

runr...@gmail.com

unread,
Sep 21, 2017, 12:14:44 PM9/21/17
to web2py-users
aww chapter 12 how I have avoided thee.  Thanks Leonel I will give it a go. 
Reply all
Reply to author
Forward
0 new messages