[英]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. 我正在尝试创建一个自定义注册视图/表单,并使其与auth.register()一起使用,但是到目前为止,我还没有运气。 I mainly have two problems. 我主要有两个问题。
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). 如果我未在控制器中包含response.view = 'register.html'
,则链接register.html默认为web2py的默认注册页面(可以,但我不想使用)。
If I removed the response.view = 'register.html'
from my controller func, then my custom form/view appears, but doesn't submit/validate. 如果我从控制器功能中删除了response.view = 'register.html'
,那么我的自定义表单/视图就会出现,但不会提交/验证。 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. 我已经阅读过的每个线程都说要在控制器中指定form = auth.register()并在视图中使用{{= form.custom.end}},但这似乎行不通。 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. 我还尝试将表单的回调操作指定为action="{{=URL('default', 'register')}}
,但是如果添加此页面,则页面也不会对提交执行任何操作。
Here's my code: 这是我的代码:
Controller: (In default.py) 控制器:(在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) 查看(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 . 您需要将查看器代码放入文件default / register.html而不是register.html中。 Then it works for me. 然后它对我有用。 You can see the resulting entry in the database. 您可以在数据库中看到结果条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.