Name Field on Anvil Default Sign Up Form?

Hi All,

It would be great to have the option to add First and Last Name to the Anvil User sign up form.

I am using the Anvil sign up form now for new users (as opposed to Facebook or Google), and if I want to capture their Name in my User data table, the user will have to sign up, then add it to their account later.

Would be great to just capture it up front.Thanks! -Ian

image

Hey @ian.monat,

You can make up your own registration form, with anything you like! anvil.users.login_with_form() is just a convenience function. You can do the actual logins and signups with anvil.users.login_with_email(email, password) and anvil.users.signup_with_email(email,password), etc. Full docs are here (look under “Python API”).

How I’d recommend doing custom sign-up is this:

  • Make a custom sign-up form (using TextBox components to collect email, password and name)

  • Call signup_with_email() from a server function. It returns the new row from the Users table, so as long as you’re on the server you can update it.

Eg:

In your signup form:

  def signup_btn_click(self, **event_args):
    # This function gets called when the button is clicked
    if self.password_box.text != self.password_repeat_box.text:
      self.error_lbl.text = 'Retyped passwords do not match'
      return
    try:
      anvil.server.call('custom_signup', self.email_box.text, self.password_box.text, self.name_box.text)
    except anvil.users.UserExists:
      self.error_lbl.text = 'This user is already registered; try logging in instead.'

In a server module:

@anvil.server.callable
def custom_signup(email, password, name):
  new_user = anvil.users.signup_with_email(email, password)
  new_user['name'] = name

And there you have it!

You could also choose to implement your own login form rather than using login_with_form(), or you could have a Login button that calls anvil.users.login_with_form(show_signup_option=False), which disables the default signup form (ie it only allows login).

3 Likes

Thank You

Is there a way to edit the existing signup form, or do we have go custom route.
Can we access the template.

Thank You

Custom route is the way to do it, aside from the options available for the Users Service.

Welcome to the forum, by the way!