Click to See Complete Forum and Search --> : form with in a form??


crabjoe
02-14-2008, 08:30 AM
Here's what I'm trying to do.

Lets say I have a form with the following fields:

Name
Address
City
State
Zip
Telephone Number
Product Sold

What I want on this form are 2 buttons. An "Update" button next to "Name" and a "Submit" button at the bottom.

Now here's what I want it to do.

What I want is to be able to enter then Name, hit "Update" and if the name is found in the database, I want the rest of the fields auto filled, except for the Product sold. If no name is found, all the fields will remain input boxes.

I know how to do this if I use 2 forms, but I'd like to do it all on the same page. I know it's possible because I've seen it done.

Can anyone point me to an example or is it something that so easy, that I just thinking it it's harder then it really is.

BTW, don't worry about the query to pull the data, because I've got that all ready. I just need to know how to do a form within a form. Basically one submit takes it back to the same page and the 2nd submit taking the data to a different page.

Thanks!!

KDLA
02-14-2008, 09:32 AM
To me, what you're describing are two forms, not necessarily "nested." You would have the name field with a submit button, and the unpopulated input fields hidden, and on submit of the "name" have them appear within the same form. Then, the user can update the fields. If the name isn't in the database, an error message could appear with the input fields saying "you aren't currently registered" or something like that. To me, it just seems like "if" and "else" statements -- nothing really complicated.

KDLA

ray326
02-14-2008, 01:23 PM
It's just one form (view) with alternative processes in the action (controller). Make both buttons submit buttons with the same name ("button"?) and different values ("submit", "update"). Test the value with your form handler and act accordingly. Or just use one button and act based on the presence of the name submitted.

crabjoe
02-14-2008, 02:28 PM
Found out nested Forms can't be done. :( As for have 2 buttons and each doing something different, well I figured out what I need to do. It's basically what Ray326 says.

What I now have is a Form with different submit values. Depending on the value, the next page auto forwards to what I need.

Thanks for your input everyone!!