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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:50:16+00:00 2026-05-25T15:50:16+00:00

I have two entities involved in this issue. A user can have an event

  • 0

I have two entities involved in this issue. A user can have an event that has multiple pieces of equipment tied to it. I need a form that the user can enter hours and roi for that piece of equipment at that particular event. Equipment in this case is actually an entity in the middle of two other entities (equipment and event) to create a many to many with extra parameters. So equipment has the fields ‘hours’ and ‘roi’. I would like to have my form dynamically added a field for hours and roi for each piece of equipment on the event. I can get up to this part. The part I have issues, is adding the elements to the form. A page that I’ve been looking at to try and help me: Zend_Form – Array based elements?.

However, in that question, they don’t seem to be doing the same thing I wish to do.

Here’s what I have right now:

foreach ($event['equipment'] as $equipment)
{
  $form->addElement('text', 'roi', array(
    'label' => $equipment['equipment']['model'] . ' ROI', 
    'required' => true,
    'belongsTo' => strval($equipment['id'])
  ));
  $form->addElement('text', 'hours', array(
    'label' => $equipment['equipment']['model'] . ' Hours', 
    'required' => true,
    'belongsTo' => strval($equipment['id'])
  ));
}

However, with this method, only the last piece of equipment’s information is shown. If there’s a way to set this up that I’m not thinking of, please let me know. I just need to be able to parse through an array of data at the end and I’ll be able to take it from there.

Thanks for your help in advance.

  • 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-25T15:50:17+00:00Added an answer on May 25, 2026 at 3:50 pm

    You are adding the same element every loop pass. The second parameter to addElement is the element identifier (roi and hours in your case).

    A possible alternative could be the following:

    foreach ($event['equipment'] as $equipment)
    {
      $form->addElement('text', 'roi' . $equipment['id'] , array(
        'label' => $equipment['equipment']['model'] . ' ROI', 
        'required' => true,
        'belongsTo' => strval($equipment['id'])
      ));
      $form->addElement('text', 'hours' . $equipment['id'], array(
        'label' => $equipment['equipment']['model'] . ' Hours', 
        'required' => true,
        'belongsTo' => strval($equipment['id'])
      ));
    }
    

    (by appending the ID to each element name/identifier).

    There could be other solutions, but you always need to have unique identifiers for each element you add to the form.

    Hope that helps,

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

Sidebar

Related Questions

I have two entities User and Event. Each user has a list of events
I have two entities one is Event and another is User. User can like
I have two entities: User and Event. Each user has a list of events
Say we have two entities:teacher and student. each teacher has multiple student. Now I
i have two entities page and user. the page has a property userId on
I have two entities User and Course. A user can take several courses which
i have two entities one called User and another called Membership which has a
I have two entities: Patient and Job. Patient has a to-many relationship to Job
i have two Entities, Parent and Child, that are linked through a bidirectional one-to-many
I have two entities, a User and Role with a one-to-many relationship from user

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.