Using Symfony I created a form in the backend. I have a submit button, which is used to save the form. I need to add another link (besides submit button) to the form that is supposed to send form data like submit button. Via this link I will be working on the submitted data via another method in the controller.
I have tried link_to('Link', '/backend_dev.php/question/edit?id='.$question->getId(), array('post' => true)) and link_to('Link', '/backend_dev.php/question/edit?id='.$question->getId(), array('method' => 'post')), but these functions do not send form data.
Controller
public function executeSave(sfWebRequest $request)
{
$this->form = new SomeForm(SomePeer::retrieveByPk($request->getParameter('id')));
if($request->isMethod('post'))
{
$this->form->bind($request->getParameter('some'), $request->getFiles('some'));
if ($this->form->isValid())
{
$some = $this->form->save();
$this->redirect('some/edit?id='.$some->getId());
}
}
}
public function executeLink(sfWebRequest $request)
{
// Like executeSave I need form data here
}
Use jQuery with an onClick event on the link which will change the
actionattribute of the form and submit it. Assuming the link has an idmyLinkand the form an idmyForm: