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

  • Home
  • SEARCH
  • 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 8395263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:15:19+00:00 2026-06-09T20:15:19+00:00

I have a form that has multiple entries to the same table, the problem

  • 0

I have a form that has multiple entries to the same table, the problem I’m having is that it only sends the last entry to the database and doesn’t send the rest. I have used the debug and it only prints out the last field in the form.

With each iteration of field its meant to input into the fields_invoices table a invoice_id, field_id, entered_value

Here is my form

<?php echo $this->Form->create('FieldsInvoice'); ?>
    <?php foreach ($fields as $field): ?>
    <?php echo $this->Form->hidden('FieldsInvoice.id'); ?>
    <?php echo $this->Form->hidden('FieldsInvoice.field_id', array('default' =>$field['Field']['id'])); ?>
    <?php echo $this->Form->input('FieldsInvoice.invoice_id', array('default' =>$invoice_id, 'type'=>'hidden')); ?>
    <?php echo $this->Form->Input('FieldsInvoice.entered_value',  array('label'=>$field['Field']['name'], 'default' =>$field['Field']['default_value'])); ?>
    <?php endforeach ;?>
    <?php echo $this->Form->End('Submit');?>

Here is the related controller

    public function create($id)
    {   
    $this->set('title_for_layout', 'Create Invoice');
    $this->set('stylesheet_used', 'homestyle');
    $this->set('image_used', 'eBOXLogoHome.png');   
    $this->layout='home_layout';


     if (!is_numeric($id)) throw new BadMethodCallException('I need an ID');
     $this->Invoice->id = $id;
     if (!$this->Invoice->exists()) throw new NotFoundException('Invalid ID');

    $this->set('invoice_id',$id);

    $names = $this->Invoice->find('list',array(
    'fields'=>array('template_id'),
    'conditions'=>array('id'=>$id)));

    $fields = $this->Field->find('all', array(
      'conditions'=>array(
     'template_id'=>$names)));

    $this->set(compact('fields'));
    $this->set(compact('invoice_id'));

    $this->set('name',$names);
    $this->Invoice->create();
    if(empty($this->data)){
        $this->data= $this->Field->read($id);
    } 
    else{
        if($this->request->is('post'))
        {
            //die(debug($this->data));

            $this->Invoice->create();
            if($this->FieldsInvoice->save($this->request->data, array('deep'=>true)));
            {
            $this->Session->setFlash('The field has been updated');
            $this->redirect(array('controller'=>'invoices', 'action'=>'index'));

            }
            //else{
            $this->Session->setFlash('Could not be saved');
            //}
        }
    }
}









\app\Controller\InvoicesController.php (line 134)
array(
    'FieldsInvoice' => array(
        (int) 0 => array(
            'id' => '',
            'field_id' => '0',
            'invoice_id' => '97',
            'entered_value' => '1'
        ),
        (int) 1 => array(
            'id' => '',
            'field_id' => '99',
            'invoice_id' => '97',
            'entered_value' => '2'
        ),
        (int) 2 => array(
            'id' => '',
            'field_id' => '999',
            'invoice_id' => '97',
            'entered_value' => '3'
        ),
        (int) 3 => array(
            'id' => '',
            'field_id' => '9999',
            'invoice_id' => '97',
            'entered_value' => '4'
        )
    )
)
  • 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-06-09T20:15:21+00:00Added an answer on June 9, 2026 at 8:15 pm

    To post multiple fields, use:

    foreach ($fields as $idx => $field):
        echo $this->Form->hidden('FieldsInvoice.'.$idx.'.id');   
        echo $this->Form->hidden('FieldsInvoice.'.$idx.'.field_id', ...);
        ...
    

    and then use $this->FieldsInvoice->saveMany() (instead of ->save()) to save multiple records.

    • 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 multiple select drop down. a user can
i have form that has multiple input text boxes, Which has got some text
If I have a form element that has multiple validators attached to it (3
I have a form that has all the fields pulled dynamic from a database
I have a form that has multiple select drop downs. i.e. Item 1: <select
I have a main form that has multiple buttons on it that will allow
i have a form that has select element <select name=adddisplaypage[] id=adddisplaypage multiple=multiple> <option value=all
I have a form that has multiple fields, and for testing purposes is there
We have a form that has multiple fields of different data type, including string,
Alrighty then, howdy first off; quick question I have a form that has multiple

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.