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 8385933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:47:24+00:00 2026-06-09T17:47:24+00:00

hi all I’m trying to add information to the database using a hasMany with

  • 0

hi all I’m trying to add information to the database using a hasMany with joins association

Invoice - id, sender_id, receiver_id, template_id
Field - id, name, description, default_value, template_id
fields_invoices - id, invoice_id, field_id, entered_value

here is the view

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

here is the 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');
            //}
        }
    }
}

here is whats printed when debug is used

\app\Controller\InvoicesController.php (line 134)
array(
    'FieldsInvoice' => array(
        (int) 87 => '',
        (int) 0 => '',
        'invoiceno' => 'test1',
        (int) 99 => '',
        'duedate' => 'test2',
        (int) 999 => '',
        'amount' => 'test3',
        (int) 9999 => '',
        'description' => 'test4'
    )
)

all the correct information is there but not submitting to the right place, the first int is the invoice_id, the other other int’s are field_id and ‘test1′,’test2′,’test3′,’test4’ are the entered_value. somehow I need to code my view so that it saves an invoice_id,field_id,test1 in the same array, how can I acheive this?

  • 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-09T17:47:25+00:00Added an answer on June 9, 2026 at 5:47 pm

    Not sure why you are creating 2 hidden fields for each of the fields.

    First read this: http://book.cakephp.org/2.0/en/models/saving-your-data.html#saving-related-model-data-hasone-hasmany-belongsto

    echo $form->input('Account.0.name', array('label' => 'Account name'));
    echo $form->input('Account.0.username');
    echo $form->input('Account.0.email');
    

    And then further reading: http://book.cakephp.org/2.0/en/models/saving-your-data.html#saving-hasmany-through-data

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, I'm inserting some text from a textarea in a mySQL database. I'm using
All, I am just trying to get the zpipe demo working using dev-c++ where
All, If I've go the following database fields/values: user_id field_name field_value 1 EventHour1 1
all. We're trying to get some intersect collisions working, but the problem experience is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
All, I am building a small site using PHP. In the site, I receive
All, I am trying to create a table to receive user inputs (UGC). This
All, I'm using wordpress with this and for some reason the eventDrop stopped working.
All, I'm using Facebook Connect (JS SDK) to authenticate a user to my site.
all, I am trying to multiply a matrix to a vector in OpenGL, but

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.