This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » Unset embedded form before validation happens [SOLVED]
Unset embedded form before validation happens [SOLVED] [message #103122] Tue, 27 July 2010 11:43
letbeserious  is currently offline letbeserious
Messages: 97
Registered: May 2007
Member
what is the right way unsetting embedded form before validation happens?

Here's the scenario, I have a main form which embeds 5 child forms,
each child form has a widget checkbox "skip this item", some fields may have invalid values, so if validation fails for this form I want user to tick "skip this item" checkbox and this form will be ignored from validation & further saving to database.


here's my form
<?php

/**
 * events module configuration.
 *
 * @package    events
 * @subpackage events
 * @author     Your name here
 * @version    SVN: $Id: configuration.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ImportEventItemsForm extends BaseEventsForm
{
	public function configure()
	{
		parent::configure();


		$subForm			= new sfForm();
		$count		= 5;
		for ($i = 0; $i < $count; $i++)
		{
			$eventItem		= new EventsItems();
			$eventItem->setEvents($this->getObject());
				
			$form		= new AddEventItemsForm($eventItem);
			$form->setDefaults(array(
				'name'		=> 'test value',
	      'city'           => 'test',
	      'venue'          => 'test',
	      'state_province' => 'test',
	      'date'           => date('c'),
	      'display_date'   => 'test',
	      'event_id'       => (int) microtime(),
			));
			
			$subForm->embedForm($i, $form);
		}
		
		$this->embedForm('Event_Items', $subForm);
	}

	public function bind(array $taintedValues = null, array $taintedFiles = null)
	{
		if (isset($taintedValues['Event_Items']))
		{
			foreach ($taintedValues['Event_Items'] as $key => $eventItem)
			{
				if ( isset($eventItem['skip_item'] ))
				{
				// here I can unset values, but how I can unset this embedded form?
	unset($taintedValues['Event_Items'][$key]);
					unset($taintedFiles['Event_Items'][$key]);
				}
			}	
		}
		
		return parent::bind($taintedValues, $taintedFiles);
	}
}


Thanks to this post - http://forum.symfony-project.org/index.php/m/90274/?srch=uns et+embedded+form#msg_90274

here's working method

public function bind(array $taintedValues = null, array $taintedFiles = null)
	{
		if (isset($taintedValues['Event_Items']))
		{
			foreach ($taintedValues['Event_Items'] as $key => $eventItem)
			{
				if ( isset($eventItem['skip_item'] ))
				{
					unset(
	          $this->embeddedForms['Event_Items'][$key],
	          $this->validatorSchema['Event_Items'][$key],
	          $taintedValues['Event_Items'][$key],
	          $taintedFiles['Event_Items'][$key]
        	); 
					
				}
			}	
		}



Please help guys!

[Updated on: Tue, 27 July 2010 12:07]

Previous Topic:Twig and Symfony 1.4
Next Topic:[SOLVED]sfForkedDoctrineApplyPlugin new Installations problems
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software