[FLOW3-general] Edit Form with two seperate target actions

Jan Greth jan at greth.me
Fri Sep 28 10:31:32 CEST 2012


Hi John,

thanks for your advice. But when I use the Buttons

/*********************************************************************/
<f:form.submit value="Speichern und zurück" name="saveAndBack" /> 
<f:form.submit value="Speichern" name="saveAndBack" />
/*********************************************************************/

and then try to make a decision in my controller / action

/*********************************************************************/
/**
  * Updates the given location object
  *
  * @param \JPG\Trainings\Domain\Model\Location $location The location 
to update
  * @return void
  */
public function updateAction(\JPG\Trainings\Domain\Model\Location 
$location, $saveAndBack = 'default') {

if(($location->getLan() == '')||($location->getLat() == '')) {
	$this->findCoordinates($location);
}


if($saveAndBack == 'Speichern und zurück'){
	$this->redirect('edit', 'Location', NULL, array('location' => $location));
	} elseif($saveAndBack == 'Speichern') {
		$this->locationRepository->update($location);
		$this->addFlashMessage('Updated the location.');
		$this->redirect('index');
	}
}
/*********************************************************************/

I get "Uncaught Exception in FLOW3"...
See: http://pastebin.com/jSeZbr5G for the full Exception.

What am I doing wrong?

Bye,
Jan




Am 27.09.2012 20:28, schrieb John Small:
> Hi,
>
> not tested in this specific way,
>
> you could name your submit-buttons then you have the value of the
> clicked button in your action-method.
> then in the action-method you can choose where to go with different
> redirect-calls depending on that value.
>
> To use the additional value in your action method just add it in the
> header of the method:
>
> public function updateAction(Someobject $someobject, $buttonname =
> 'default') {
>      ...
>
>      if ($buttonname ...)
>          ...redirect('here');
>      else
>          ...redirect('there');
> }
>
>
> if you have to provide an object for the action method you want to
> redirect to add it to the redirect call, e.g.
>
>      $this->redirect('show', 'Controllername', NULL, array('someobject'
> => $someobject));
>
>
> HTH
>
>
> Am 27.09.2012 15:11, schrieb Jan Greth:
>> Hey Folks,
>>
>> I have an simple Edit-form like the one autogenerated by the FLOW3 CLI.
>> Looks like this:
>>
>> /*********************************************************************/
>> <f:form action="update" object="{location}" name="location">
>>   <ol>
>>     <li>
>>       <label for="title">Title</label>
>>       <f:form.textfield property="title" id="title" />
>>     </li>
>>
>>     <li>
>>       <label for="street">Street</label>
>>       <f:form.textfield property="street" id="street" />
>>     </li>
>>
>> [...]
>>
>>     <li>
>>       <f:form.submit value="Save and back"/>
>>     </li>
>>   </ol>
>> </f:form>
>> /*********************************************************************/
>>
>> But now I have the problem that I would like to have two send buttons.
>> One for "Save and back" and one just for "Save" (User stays on page)
>>
>> How would you implement it?
>>
>> I had thoughts of writing a new action - but Action is set in form
>> head not in button...
>>
>> Bye,
>> Jan
>



More information about the FLOW3-general mailing list