First check if idmensajes exist, and if you can get another field from your form.
Try this:
$this->form['idmensajes']->getValue(),
upd
Try:
$mensajes = $form->save();
$idmensajes = $mensajes->getIdmenSajec()// or other getter
Question
When I create a new record, in the action processForm
I need to get the value of a hidden field called idmensajes
. This field is a hidden field, auto-incremental and prymary key.
But when I use getValue ('idmensajes')
the result is empty. Why? How I can get the value of idmensajes in processForm?
Here the code of processForm
:
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid())
{
$form_vals = $this->form->getValue('idmensajes');
$mensajes = $form->save();
$this->redirect('mensajes/index');
In order to view captured values, corresponding to two fields, I added:
$form_vals1 = $this->form->getValue('idmensajes');
$form_vals2= $this->form->getValue('cuerpo');
$this->getUser()->setFlash("val1", $form_vals1);
$this->getUser()->setFlash("val2", $form_vals2);
In the view, indexSuccess.php, I add the code:
<?php echo 'El valor del Id es:'. $sf_user->getFlash('val1'); ?>
<br>
<?php echo 'El valor de Cuerpo es: '. $sf_user->getFlash('val2'); ?>
Then, I view the value of val2
but the value val1
is empty.
Here the complete code, with Flash add:
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid())
{
$mensajes = $form->save();
$form_vals1 = $this->form->getValue('idmensajes');
$form_vals2= $this->form->getValue('cuerpo');
$this->getUser()->setFlash("val1", $form_vals1);
$this->getUser()->setFlash("val2", $form_vals2);
$this->redirect('mensajes/index');
Solution
First check if idmensajes exist, and if you can get another field from your form.
Try this:
$this->form['idmensajes']->getValue(),
upd
Try:
$mensajes = $form->save();
$idmensajes = $mensajes->getIdmenSajec()// or other getter