Hi,
I tried to insert rows of the same table from different forms in
different pages.
Example: user table has name, address, telephone number and hobbies.
I have two pages with one form in each page. One form in the page has
name and address fields while the other form in the other page has
telphone number and hobbies fields. All of the fields cannot be null. I
need to be able to post these fields from those two different forms.
Considering that the data from the first form cannot be saved yet
because of validation, all you need to do is to add hidden fields that
relate to the attributes from the first form.
Say the first form is to change name and the second to change address,
you would add in the second a hidden field that uses @user.name.
This will work if you are using @user = User.new(params[:user]) to
initiate the user object on every form.
It will get nasty when you try to validate the user though, cause he
will go trough all forms without errors and on the last one might get
an error that “Name” (from first form) is blank.
My advice is to add all fields who need to be present for the model to
pass validation on the first form. Considering a user object, this
would usually be username, password and email. Then you show the user
some reminders to update his address in case he have an empty one.
Remember, make the “sign up” forms short and quick. Ask the user to
fill additional but not that critical data later…
Considering that the data from the first form cannot be saved yet
because of validation, all you need to do is to add hidden fields that
relate to the attributes from the first form.
Say the first form is to change name and the second to change address,
you would add in the second a hidden field that uses @user.name.
This will work if you are using @user = User.new(params[:user]) to
initiate the user object on every form.
It will get nasty when you try to validate the user though, cause he
will go trough all forms without errors and on the last one might get
an error that “Name” (from first form) is blank.
My advice is to add all fields who need to be present for the model to
pass validation on the first form. Considering a user object, this
would usually be username, password and email. Then you show the user
some reminders to update his address in case he have an empty one.
Remember, make the “sign up” forms short and quick. Ask the user to
fill additional but not that critical data later…
So what the previous posting means is for me to post the fields from the
first form to the second form in hidden fields? And does this work for
update as well?
Now I don’t understand you anymore. My examples were for a simple user
form, where you edit basic stuff like name on the first form and
address on the second one. And I understood that they were
“sequential”, as in a 2 step thing. If they are not sequential then
this does not apply.
I need you to explain better, with real code if possible what the
model is and what data you want to change on the first form and what
data you want to change on the second form.
So what the previous posting means is for me to post the fields from the
first form to the second form in hidden fields? And does this work for
update as well?
Thanks,
user splash
To add on to the previous postings, I have to create 100 over rows.
Won’t it over load the form by hidding these fields? And I would love to
know how can I insert more than one rows into a column all at the same
time?
Option 1:
have the entire form on one page, where you put the form on separate
tabs. The tabs would be hidden + selectable via DHTML + Javascript
Option 2:
User.save_without_validation, storing the user id either in session or
flash, or params, or have a hidden_field_tag which carries the user id
along with each form.
Option 1:
have the entire form on one page, where you put the form on separate
tabs. The tabs would be hidden + selectable via DHTML + Javascript
Option 2:
User.save_without_validation, storing the user id either in session or
flash, or params, or have a hidden_field_tag which carries the user id
along with each form.
The forms I am going to create might not be in step 1 step 2 sequence.
As user can skip step 1 or 2 and move directly to step 3 then come back
to do the steps he/she has skipped.
Option 1:
have the entire form on one page, where you put the form on separate
tabs. The tabs would be hidden + selectable via DHTML + Javascript
Option 2:
User.save_without_validation, storing the user id either in session or
flash, or params, or have a hidden_field_tag which carries the user id
along with each form.
The forms I am going to create might not be in step 1 step 2 sequence.
As user can skip step 1 or 2 and move directly to step 3 then come back
to do the steps he/she has skipped.
Thanks,
fries 88
Hi,
Sorry if I sound confusing. What I am required to do here is to create
a new user. There are three pages here.
Page 1: save username and password into user table
Page 2: save address, telephone number and gender into user table
Page 3: save hobbies and favourites into user_info table
The user does not have to browse around these pages in sequence. I have
tried many ways and have yet to get this working. Anyone please, how can
I acheive this.
Hi,
Sorry if I sound confusing. What I am required to do here is to create
a new user. There are three pages here.
Page 1: save username and password into user table
Page 2: save address, telephone number and gender into user table
Page 3: save hobbies and favourites into user_info table
The user does not have to browse around these pages in sequence. I have
tried many ways and have yet to get this working. Anyone please, how can
I acheive this.
Thanks,
fries 88
Sorry I miss out this part:
All the fields in user table cannot be null
Hi,
Sorry if I sound confusing. What I am required to do here is to create
a new user. There are three pages here.
Page 1: save username and password into user table
Page 2: save address, telephone number and gender into user table
Page 3: save hobbies and favourites into user_info table
The user does not have to browse around these pages in sequence. I have
tried many ways and have yet to get this working. Anyone please, how can
I acheive this.
Thanks,
fries 88
Sorry I miss out this part:
All the fields in user table cannot be null
Hi,
I have tried the secong option suggested by Gammons and it still cant
work. I dont understand the first option. Can someone please further
explain or provide another option to this problem?
Thanks,
fries 88
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.