SibinF
SibinF

Reputation: 385

How to get data from multiple form elements within a single view

I have added three form elements

  1. defineroute.ctp
  2. singleroute.ctp
  3. singletrip.ctp
    in a view called route.ctp.there is a function for the route.ctp in the users_controller called route(). my doubt is how to manage the data coming from these three elements and store it in different tables. how it is possible?

Upvotes: 0

Views: 124

Answers (1)

Kapil
Kapil

Reputation: 1810

Sibin,

There are many ways to do it.

  1. As you have separate elements that menas you have create different-different form tags for all different form and once they are submitted then it will go to specific controller and action so it is very simple here.

  2. If you have kept one form tag for all your element then you can keep your text boxes name different for different-different models.

like:

For defineroute.ctp

data[model1][field1] data[model1][field2]

singleroute.ctp data[model2][field1] data[model2][field2]

singletrip.ct

data[model3][field1] data[model3][field2]

Once they form is submitted then you will one array containing different model array like:

data[model1]=>array(field1, field2) data[model2]=>array(field1, field2) data[model3]=>array(field1, field2)

Now you can perform save action and enjoy madi!!!

Upvotes: 1

Related Questions