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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:06:22+00:00 2026-05-15T17:06:22+00:00

I been trying all day to do multiple insert for the same form based

  • 0

I been trying all day to do multiple insert for the same form based on a number and i couldn’t go any where with it. I hope someone here would be help me out…

am using admin generator on 1.4 doctrine. I have a form which i generated with only two fields. what am trying to do is, based on a number inserted the form will be repeated x number of times.

In the generator file I added a partial which placed a text field in the beginning of the form with default value of 1. If I choose 2 the form below gets duplicated twice..

Here is what i did to my form.. In action

class prizesActions extends autoPrizesActions

{
public function executeNew(sfWebRequest $request)
{

$this->form = $this->configuration->getForm(null, array('n' => 5));
$this->prizes = $this->form->getObject();

}
}

and in the PrizesForm, I wrote the following

class PrizesForm extends BasePrizesForm

{
public function configure()
{
$array = $this->getOptions();
for ($i = 0; $i < $array[‘n’]; $i++) {

    $this->setWidgets(array(
      'id'         => new sfWidgetFormInputHidden(),
      'prize_no'   => new sfWidgetFormInputText(),
      'prize'      => new sfWidgetFormInputText(),
      'created_at' => new sfWidgetFormDateTime(),
      'updated_at' => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(
      'id'         => new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'column' => 'id', 'required' => false)),
      'prize_no'   => new sfValidatorInteger(array('required' => false)),
      'prize'      => new sfValidatorString(array('max_length' => 200, 'required' => false)),
      'created_at' => new sfValidatorDateTime(),
      'updated_at' => new sfValidatorDateTime(),
    ));

    $this->widgetSchema->setNameFormat('prizes['.$i.'][%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
}





unset(  $this['updated_at'],
        $this['created_at']
        );  

}
}

I think the loop is working but its over writing the widgets at every entry and i cannot find other method to append instead. Any ideas?

Thanks,

  • 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-15T17:06:23+00:00Added an answer on May 15, 2026 at 5:06 pm

    Did you try embedForm()? Code below should give you an idea.

    class PrizesForm extends BasePrizesForm
    {
      public function configure() 
      { 
        $this->setWidgets(array(
          'id'         => new sfWidgetFormInputHidden(),
          'prize_no'   => new sfWidgetFormInputText(),
          'prize'      => new sfWidgetFormInputText(),
          'created_at' => new sfWidgetFormDateTime(),
          'updated_at' => new sfWidgetFormDateTime(),
        ));
    
        $this->setValidators(array(
          'id'         => new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'column' => 'id', 'required' => false)),
          'prize_no'   => new sfValidatorInteger(array('required' => false)),
          'prize'      => new sfValidatorString(array('max_length' => 200, 'required' => false)),
          'created_at' => new sfValidatorDateTime(),
          'updated_at' => new sfValidatorDateTime(),
        ));
    
        $this->widgetSchema->setNameFormat('prizes[%s]');
      }
    }
    
    class PrizesGroupForm extends sfForm
    {
      public function configure() 
      { 
        $array = $this->getOptions();
    
        for ($i = 0; $i < $array['n']; $i++) 
        {
          $this->embedForm('prizes_' . $i, new PrizesForm());
        }
    
        $this->widgetSchema->setNameFormat('prizes_group[%s]');
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to solve this problem all day but haven't got any
I have been trying all day to get some data properly formatted in a
I've been trying all day with no luck to regex replace the new line
I've been trying to get this working correctly all day, its nearly complete just
I've been trying to get some animated models from c4d into Blender all day.
Hey guys I've been trying all day to get an ant file to automatically
I have been trying to solve this problem all day, I googled a lot,
I've been trying to solve this problem all day. I just want to list
well I have been trying to get Nivo Slider to work almost all day.
I'm new to python and have been trying to figure this out all day.

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.