简体   繁体   中英

Help with data transfer/storage from one HTML form to another

In my application, I have two forms for creating a user.
Form 1: I input the following details from the user in form 1.

  • Full Name
  • Email Address
  • Gender
  • Date of Birth
  • Profile Image

AND in the Form 2, I ask him to fill in his

  • desired @username, and
  • password

Problem is that I have associated my models in the following fashion, that

User has_one UserProfile  
UserProfile belongs_to User  

&

Email Address, username and password are attributes of User model.
The rest of the attributes belong to UserProfile model.

But in my forms, I am using Email Address in Form1 and the other attributes in Form2.

Should I make the forms as Rails forms or plain HTML forms?
How should I do this???

UPDATE:- I don't want to create a UserProfile Object without creating a User object, so I need some way to store the form 1 values in javascript, and then when Form 2 gets submitted, then pass them both to Rails controller method.

I dont know much about ruby but whats the need to complicate the process.. Have one form and visually you can separate the fields using maybe two fieldsets. Then submit the form and at the backend save them any way you want.

I don't see the need to create both UserProfile and User but if you do have to create it, and you first have to fill in form1 which is UserProfile and only then form2 which is User then you could create the following.

On the form1 first create a User.new and use User.save, then you have the new User.id and supposingly a new UserProfile has been created with the :reference to user_id,

(be aware that your validation process is more difficult because now if you validate :username it is null and therefore not unique nor whatever, you could make User.new defaults and call the data 'tempUser' until it is fully created.)

then you have the user_id to reference to, fill in the UserProfile, save it, redirect back to the User form, update it, validate the user entered data, and save it.

Why would you like to roll like that though?

Wouldn't having just User and retrieving the data?

Or less validation in the process would be first having the user create the User object (username, password first), only then create the UserProfile object (email and such).

There are ways to bypass all of that, it's just more complicated :(

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