开发者

Having the Login & Register form in 1 page

1st question is isit ok to have more than 1 form per page? i read dunno where that 1 page shld have only 1 form, true?

assuming you do login and register form in 1 page, i think there are 2 approaches

  • 2 separate forms -> isit ok for form input[name] to be reused? eg. both login and register will have username & passwords field
  • 1 form. use JS to hide confirmPassword field then at ser开发者_运维问答ver side check if there is a confirmPassword is filled? upon typing this, this does not seem like a good idea...


1st question is isit ok to have more than 1 form per page?

Yes, it's ok.

isit ok for form input[name] to be reused? eg. both login and register will have username & passwords field

Yes, it's ok. You can place two inputs with the same name (in different forms). Only 'id' attribute must be unique. You should set different actions for form. For example, the first form will be <form action='login.php'>, the second - <form action='register.php'>

1 form. use JS to hide confirmPassword field then at server side check if there is a confirmPassword is filled? upon typing this, this does not seem like a good idea...

It's better to create input with type=hidden and place action type in it:

<input type='hidden' name='action' value='login'>

You can change value with Js.

Also you can create two submit buttons in one form:

<input type='submit' name='do_login' value='Login'>
<input type='submit' name='do_register' value='Register'>

If login button pressed, the server will receive 'do_login' argument. Else, it will receive 'do_register'.


You can have as many forms as you want on a page. There's no restriction, just think about whether it makes sense or not.

If you're going to have more than 1 form, it's fine to duplicate field names if they both do the same job. But they may or may not be posting to a different location, so make sure you either do that, or include a hidden field to differentiate which form was completed.

Don't use JS to hide fields, make the form work without JavaScript if possible then enhance it with JS later.


Here's a website I used to be the webmaster for, they have an intuitive (from the UI side, anyways) way of getting people to register or login in one page:

https://www.usacycling.org/myusac/index.php?pagename=login

Note that if you register (on the left) it takes you to another (larger) registration form that gathers more specific information. This allows a good quality registration information gathering mechanism while not overwhelming the user.

It's been a while, but I believe that this example was handled with two separate forms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜