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 » legacy support » symfony 1.2 » [Solved] Only save ONE of my EmbeddedForm
[Solved] Only save ONE of my EmbeddedForm [message #90850] Tue, 05 January 2010 13:50 Go to next message
tioz  is currently offline tioz
Messages: 16
Registered: October 2009
Junior Member
Hi guys,

I have a main form A and several embedded forms of type B. I added a "save"-Button to each embedded form. On click, only THIS EMBEDDED FORM should be saved - nothing else.

My problem: How to update/ save this embedded form? At the moment I get the ID of my embedded form to my action.class. I can extract this object from my database. But I somehow need to update it, so how do I get the updated values (?).

I do NOT want to save the whole form!


Thanks in advance,
tioz

[Updated on: Thu, 07 January 2010 16:11]

Re: Only save ONE of my EmbeddedForm [message #90914 is a reply to message #90850 ] Wed, 06 January 2010 15:34 Go to previous messageGo to next message
tioz  is currently offline tioz
Messages: 16
Registered: October 2009
Junior Member
Additional question:

Is there any way I can FIRST save my complete form (main+embedded) and THEN add a new embedded form with ONE click?

E.g. if I click the button "add embedded form", I want to traverse the whole "save" process - including executeUpdate, processForm, show errors, etc... and afterwards I want to add a new embedded form.

If I try to embed a new form BEFORE the processForm-call in the executeUpdate method in the action.class, he tries to save the new embedded form as well - which is invalid of course.

If I try to embed a new form AFTER the processForm-call in the executeUpdate method in the action.class, it's unreachable code.

[EDIT: SOLVED]
In your processForm, add a parameter in the

$this->redirect


call. Then you can add an if-Statement in your executeEdit method

if($request->hasParameter('ASDF')) {


and there you can embed the new form.

But my first problem is NOT SOLVED (!) Sad

[Updated on: Wed, 06 January 2010 16:42]

Re: Only save ONE of my EmbeddedForm [message #90965 is a reply to message #90850 ] Thu, 07 January 2010 16:11 Go to previous messageGo to next message
tioz  is currently offline tioz
Messages: 16
Registered: October 2009
Junior Member
Solved.

Use

<?php echo link_to('<input type="image" 
src="/web/images/save.png" 
class="icon" 
name="submit" 
value="save_'.$embeddedForm->getObject()->getId().'">', 
'asdf/saveAsdf?id='.$form->getObject()->getId().'&asdfId='.$embeddedForm->getObject()->getId()); ?>


Instead of

<input type="image" src="/web/images/save.png" class="icon" name="submit" value="save_<?php echo $embeddedForm->getObject()->getId() ?>">
Re: Only save ONE of my EmbeddedForm [message #99167 is a reply to message #90965 ] Sun, 16 May 2010 23:09 Go to previous messageGo to next message
kanail  is currently offline kanail
Messages: 10
Registered: May 2008
Location: Paris
Junior Member
Hi,
I want to do the same as you (bind only some embeddeds form) but I can't because your method seems to be different from mine.
Your method:
In your action, you are saving Doctrine objects directly without passing by forms (you don't clear and validate your data with
form->bind
...

My method:
I get back my form and my embedded forms from the request and as you I only want to save SOME embedded froms.
This is how I do it:
in my Action class:
if (some conditions...)
{
  $alphaForms = $this->form->getEmbeddedForm('Alpha')->getEmbeddedForms();
foreach($alphaForms  as $alphaForm )
{
$this->processForm($request, $alphaForm);
}
}	
else
{
$betaForm = $this->form->getEmbeddedForm('new');
$this->processForm($request, $betaForm);
}
....

here is my processForm method:
protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid())
{
      $object = $form->save();
}
else
  {
...


in the processForm method, the values of my embedded forms are always empty! It only works when I send the whole form to my processForm method -> but in this case the form has some errors when I call bind. And I don't whant to show errors. Can someone help? Thanx

[Updated on: Mon, 17 May 2010 09:55]

Re: Only save ONE of my EmbeddedForm [message #101944 is a reply to message #99167 ] Sat, 03 July 2010 08:53 Go to previous message
kanail  is currently offline kanail
Messages: 10
Registered: May 2008
Location: Paris
Junior Member
found à better way : it should be handeléd in thé form classe instead of thé action.
usé of bind and unset method

[Updated on: Sat, 03 July 2010 08:55]

Previous Topic:Using sfWidgetFormJQueryAutocompleter to complete multiple words in a text input field?
Next Topic:doctrine - strange Doctrine_Connection_Mysql_Exception
Goto Forum:
  

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