简体   繁体   中英

Web2py - How to process custom register form?

I am trying to create a custom register view/form and have it work with auth.register(), but so far I've had no luck. I mainly have two problems.

  1. If I don't include response.view = 'register.html' in my controller the link register.html defaults to web2py's default register page (which works, but I don't want to use).

  2. If I removed the response.view = 'register.html' from my controller func, then my custom form/view appears, but doesn't submit/validate. It just keeps popping the on-fail message "Oops something went wrong submitting the form"

Every thread I've read about this just says to specify the form=auth.register() in the controller and use the {{=form.custom.end}} in the view, but that doesn't seem to work. Am I missing something?

I also tried specifying the callback action for the form to action="{{=URL('default', 'register')}} , but if I add this the page won't do anything on submit either.

Here's my code:

Controller: (In default.py)

def register():
    response.view = 'register.html'
    db.auth_user.first_name.readable = db.auth_user.first_name.writable = False
    db.auth_user.last_name.readable = db.auth_user.last_name.writable = False
    return dict(form=auth.register())

View (default/register.html)

<body class="body-4">
 <div class="form-block w-form">
   <form id="email-form" name="email-form" data-name="Email Form">
     <h1 class="heading-5">Register</h1>
        <input type="email" class="text-field w-input" maxlength4="256" name="Email" data-name="Email" placeholder="Enter your email" id="Email" required="">
        <input type="password" class="text-field w-input" maxlength="256" name="Password" data-name="Password" placeholder="Enter your password" id="Password" required="">
        <input type="password" class="text-field w-input" maxlength="256" name="Password-2" data-name="Password 2" placeholder="Confirm your password" id="Password-2" required="">
        <input type="submit" value="Register" data-wait="Please wait..." class="submit-button w-button">
    {{=form.custom.end}}
    <div class="w-form-done">
      <div>Thank you! Your submission has been received!</div>
    </div>
    <div class="w-form-fail">
      <div>Oops! Something went wrong while submitting the form.</div>
    </div>
  </div>
  <script src="{{=URL('static','js/webflow.js')}}" type="text/javascript"></script>
  <!-- [if lte IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/placeholders/3.0.2/placeholders.min.js"></script><![endif] -->
</body>

You need to put the viewer code into the file default/register.html instead of register.html . Then it works for me. You can see the resulting entry in the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM