I want to convert a value before saving the form.
I don’t know where to add the code because the only method is form->save()
Could you please help me ?
Edit:
if ($this->form->isValid())
{
$url = $this->form->getObject()->getLink();
parse_str(parse_url($url, PHP_URL_QUERY), $my_array_of_vars);
$this->form->getObject()->setLink($my_array_of_vars['v']);
$song = $this->form->save();
$this->getUser()->setFlash('notice', 'Thank you, the song has been added');
$this->redirect('@homepage');
}
The @pankar answer is almost good. But the
$this->form->save()will override thesetLink.First of all, define the function to retrieve the youtube id, as defined here in a new tools class:
lib/myTools.class.phpThen, update your action with this:
By the way, this method is ok if you use your form in only one place. Since the update is perform in the action and not in the form class. Otherwise, as @glerendegui said, you will have to do this action in the form class. But I will rather do it in the
doUpdateObjectinstead ofdoSave. Since the code says:So I will do it in this way, inside your form (
lib/form/doctrine/yourForm.class.php):