Embedding multiple forms with symfony … hardcore :)

Well this should be one of the last posts about branch 1.x of symfony. The 2nd version should come to alpha soon so there is no real need to go further with it. Anyway … some time ago I desperately needed a quick and reliable way to embed multiple symfony forms on one page and submit them at once. I generally take the time to look into the source files, but this time i was in a hurry. So this is the “hacky” way i got around:

function executeMoo(sfWebRequest $request) {
$this->forms = array();

$it = 0;

foreach($some_model as $s) {

$f = new MooForm($s);

$f->getWidgetSchema()->setNameFormat('foo[' . $form->getName() . $it . '][%s]');

$this->form->embedForm($it, $form);
$this->forms[] = $this->form;
$it++;

}
}

The presentation part should be as simple as:

<form ...>
<table>
<tr>
<td><table>
<?php
foreach($forms as $form) :
   echo $form;
endforeach;
?>
</table></td>
</tr>
</table>
</form>
</pre>

Ok now for the validation part:

public function executeSubmit_Foo(sfWebRequest $request) {
         $this->forward404Unless($request->isMethod(sfRequest::POST));

   	$base_forms = $request->getParameter('foo');
    
	foreach($base_forms as $base_form) {
		$f = new MooForm();
		$f->bind($base_form,null);
		if($f->isValid()) {
			$f->save();			
		}
	}
}

What’s the catch?
Well the catch is in this line: $f->getWidgetSchema()->setNameFormat(‘foo[‘ . $form->getName() . $it . ‘][%s]’);
What it really does? it generates the form fields like foo[‘forms_name1′] … so the only thing you have to do is grabbing the foo var from request and looping through to get the embedded forms.
Sure there are better ways, but this worked nice with a minimum ammount of time spent.
Hope it helps.

Windows reloaded or failure reloaded?

Today i had some time to look inside of some newsletter i got in the last few days. One of them seemed pretty interesting because it was talking about a totally new Windows, with cool new stuff(yeah heard that before) and a complete new design(same here). While i wasn’t quite convinced about the last, i took a look at one of the videos presenting the new redesigned UI. In my oppion the changes look good, though they don’t bring something really spectacular compared to competition (in fact it shouldn’t, as it has to be still friendly for people coming from prior versions), but it’s a good change that strengthens my belief that Windows is one of the best choices for most of the people when it comes to daily computer usage. One interesting thing is that Microsoft started to impose restrictions for the Windows 8 tablet chipmakers according to windows8center.com, which in my oppinion is one of the best things they’ve did in the past decade … it should bring more quality, lower prices and most of all … a better experience(did they finally learn the apple philosophy?). – original post here

Anyway here are the videos.

And second one from the Windows 8 presentation in taiwan.
[iframe src=”http://www.microsoft.com:80/presspass/silverlightApps/videoplayer3/standalone.aspx?contentID=win8_preview1&src=/presspass/presskits/windows7/channel.xml” width=”640″ height=”360″ frameborder=”0″ scrolling=”no]

More information can be found on windows8center.com