Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7497969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:17:26+00:00 2026-05-29T19:17:26+00:00

I have a form that has all the fields pulled dynamic from a database

  • 0

I have a form that has all the fields pulled dynamic from a database table ‘FieldNames’:

ID | FieldName
--------------
11 | username
22 | password
33 | Address
44 | etc

This is just an example, the form is more complex.

I have learned and saw in php doc that if the form fields match 1:1 with the model table the Save method is user and a new row gets created with all the values in the proper cells.
But how does it work if for my sample form all fields values should get in multiple lines, one by one in a table ‘FieldValues’ with the following structure.

ID | FieldId | Value                | DataSet
---------------------------------------------
1  | 11      | 'value for username' | 1
2  | 22      | 'value for password' | 1
3  | 33      | 'value for address'  | 1

FieldId = FK to Fieldnames.ID

I was able to do this in a method using the “classic”

foreach field -> $sql = "sql insert query" -> $this->query( $sql )'

I was just wondering is i can use the “magic” in cake to solve this task.
Second question: If the “magic” is possible, how can i add a second parameter and on each data set to set a new DataSet value ?

This is a form builder app so the fields HAVE to be dynamic and I cannot use the “static” form implementation (hardcode the fields names in table columns 1:1). The field names and number vary. That’s why I’m pulling them for the database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:17:29+00:00Added an answer on May 29, 2026 at 7:17 pm

    I suggest you to create a method in your model (where you want to save your fields) like:

    // Field model
    public function saveFields($data) {
        foreach($data as $field) {
            $this->save($field);
        }
    }
    

    You can call this function in your FieldsController Add Action:

    // FieldsController
    $this->Field->saveFields($this->request->data);
    

    Or in any other Controller / Model by using ClassRegistry:

    // FooController
    $Field = ClassRegistry::init('Field');
    $Field->saveFields($this->request->data);
    

    Be sure that your data is in the proper format like:

    $data [0] [ ModelName ] = array(
        Field1 => Value1,
        Field2 => Value2 
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that has a field pulled from the database as a
Hi all I have a form that has 4 fields I can get it
I have a site that has a simple HTML button in a form. All
I have a form that has multiple fields, and for testing purposes is there
In my application I have a form that has some filter fields. None are
I have created a contact form that has a disabled submit button until all
I have a form with a table that has two input boxes, a select
I have a simple contact form on a website that has 2 text fields,
I have a form that detects if all the text-fields are valid on each
i have a form that has many input fields. some fields of them are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.