Re: Show validationerrors after a redirect

2009-02-02 Thread brian

You don't need to redirect. When you do so, the information stored in
$validationErrors is lost because you're making a new request. If you
remove the redirect() call, Cake should simply re-display the form.
Then if all is working well, FormHelper will take care of printing the
errors for you.

On Mon, Feb 2, 2009 at 3:23 PM, Mickiii michael.la...@gmail.com wrote:

 Hi,

 This is probably simple, but I can't find any specifics on it.

 I have a controller called ledger_controller, which uses two models:
 Ledgeraccount and Ledgertransaction. Within this controller i have a
 function called chartofaccounts, which includes a form, with an action
 that leads to the ledger controller, but a function called add. I
 can save the data alright, and also validate it, but I can't get the
 error messages to show... why is that?

 Controller ledger:

function add () {
if(!empty($this-data)) {
$this-Ledgeraccount-set($this-data);
if($this-Ledgeraccount-validates()) {
$this-Ledgeraccount-save($this-data, false);
$this-redirect('chartofaccounts');
} else {
$this-Session-setFlash('Venligt ret fejlene 
 herunder',
 'default', array('class'='bad'));
$this-redirect('chartofaccounts');
}
}
}

 Form in chartofaccounts.ctp

 ?=$form-create('Ledgeraccount', array('url' = '/ledger/add'));?

 ?
echo $form-input('Ledgeraccount.number');
echo $form-input('Ledgeraccount.name');
echo $form-input('Ledgeraccount.type', array('options' = array(
'header'='Header',
'sum'='Sum',
'profitloss'='Profit Loss',
'balancesheet'='Balancesheet'
)));
 ?

 ?=$form-end('Create');?


 If this is standard behaviour, then is there any way I can get the
 errormessages to show in the chartofaccounts view, without breaking
 the conventions too much?

 Thanks
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Show validationerrors after a redirect

2009-02-02 Thread Mickiii

Thanks Brian, however if I remove the redirect call it displays the
view for the function add, i.e. the add.ctp (which doesnt exists),
but I want it to go back to chartofaccounts where the form is, and
then display the errors there.

On Feb 2, 9:30 pm, brian bally.z...@gmail.com wrote:
 You don't need to redirect. When you do so, the information stored in
 $validationErrors is lost because you're making a new request. If you
 remove the redirect() call, Cake should simply re-display the form.
 Then if all is working well, FormHelper will take care of printing the
 errors for you.

 On Mon, Feb 2, 2009 at 3:23 PM, Mickiii michael.la...@gmail.com wrote:

  Hi,

  This is probably simple, but I can't find any specifics on it.

  I have a controller called ledger_controller, which uses two models:
  Ledgeraccount and Ledgertransaction. Within this controller i have a
  function called chartofaccounts, which includes a form, with an action
  that leads to the ledger controller, but a function called add. I
  can save the data alright, and also validate it, but I can't get the
  error messages to show... why is that?

  Controller ledger:

         function add () {
                 if(!empty($this-data)) {
                         $this-Ledgeraccount-set($this-data);
                         if($this-Ledgeraccount-validates()) {
                                 $this-Ledgeraccount-save($this-data, 
  false);
                                 $this-redirect('chartofaccounts');
                         } else {
                                 $this-Session-setFlash('Venligt ret 
  fejlene herunder',
  'default', array('class'='bad'));
                                 $this-redirect('chartofaccounts');
                         }
                 }
         }

  Form in chartofaccounts.ctp

  ?=$form-create('Ledgeraccount', array('url' = '/ledger/add'));?

  ?
         echo $form-input('Ledgeraccount.number');
         echo $form-input('Ledgeraccount.name');
         echo $form-input('Ledgeraccount.type', array('options' = array(
                 'header'='Header',
                 'sum'='Sum',
                 'profitloss'='Profit Loss',
                 'balancesheet'='Balancesheet'
         )));
  ?

  ?=$form-end('Create');?

  If this is standard behaviour, then is there any way I can get the
  errormessages to show in the chartofaccounts view, without breaking
  the conventions too much?

  Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Show validationerrors after a redirect

2009-02-02 Thread Mickiii

Hang on, I just found this post in the Bakery:
http://bakery.cakephp.org/articles/view/validation-in-another-controller

Does that still apply? Or has there been done anything built in stuff
in the latest version of Cake?

On Feb 2, 9:40 pm, Mickiii michael.la...@gmail.com wrote:
 Thanks Brian, however if I remove the redirect call it displays the
 view for the function add, i.e. the add.ctp (which doesnt exists),
 but I want it to go back to chartofaccounts where the form is, and
 then display the errors there.

 On Feb 2, 9:30 pm, brian bally.z...@gmail.com wrote:

  You don't need to redirect. When you do so, the information stored in
  $validationErrors is lost because you're making a new request. If you
  remove the redirect() call, Cake should simply re-display the form.
  Then if all is working well, FormHelper will take care of printing the
  errors for you.

  On Mon, Feb 2, 2009 at 3:23 PM, Mickiii michael.la...@gmail.com wrote:

   Hi,

   This is probably simple, but I can't find any specifics on it.

   I have a controller called ledger_controller, which uses two models:
   Ledgeraccount and Ledgertransaction. Within this controller i have a
   function called chartofaccounts, which includes a form, with an action
   that leads to the ledger controller, but a function called add. I
   can save the data alright, and also validate it, but I can't get the
   error messages to show... why is that?

   Controller ledger:

          function add () {
                  if(!empty($this-data)) {
                          $this-Ledgeraccount-set($this-data);
                          if($this-Ledgeraccount-validates()) {
                                  $this-Ledgeraccount-save($this-data, 
   false);
                                  $this-redirect('chartofaccounts');
                          } else {
                                  $this-Session-setFlash('Venligt ret 
   fejlene herunder',
   'default', array('class'='bad'));
                                  $this-redirect('chartofaccounts');
                          }
                  }
          }

   Form in chartofaccounts.ctp

   ?=$form-create('Ledgeraccount', array('url' = '/ledger/add'));?

   ?
          echo $form-input('Ledgeraccount.number');
          echo $form-input('Ledgeraccount.name');
          echo $form-input('Ledgeraccount.type', array('options' = array(
                  'header'='Header',
                  'sum'='Sum',
                  'profitloss'='Profit Loss',
                  'balancesheet'='Balancesheet'
          )));
   ?

   ?=$form-end('Create');?

   If this is standard behaviour, then is there any way I can get the
   errormessages to show in the chartofaccounts view, without breaking
   the conventions too much?

   Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Show validationerrors after a redirect

2009-02-02 Thread Miles J

Just change the url the form is posting to.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Show validationerrors after a redirect

2009-02-02 Thread Mickiii

Miles, is that not what the 'url' option is doing?

On Feb 2, 10:54 pm, Miles J mileswjohn...@gmail.com wrote:
 Just change the url the form is posting to.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Show validationerrors after a redirect

2009-02-02 Thread Miles J

I see what your saying, do this:

if($this-Ledgeraccount-validates()) {
   if ($this-Ledgeraccount-save($this-data, false)) {
   $this-redirect('chartofaccounts');
 }
 }
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Show validationerrors after a redirect

2009-02-02 Thread Miles J

Oops and also remove this:

} else {
$this-Session-setFlash('Venligt ret
fejlene herunder',
'default', array('class'='bad'));
$this-redirect('chartofaccounts');
}
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Show validationerrors after a redirect

2009-02-02 Thread brian

I misread your original post. I think what you need to do is call
render(), not redirect().

$this-render('chartofaccounts');

On Mon, Feb 2, 2009 at 3:40 PM, Mickiii michael.la...@gmail.com wrote:

 Thanks Brian, however if I remove the redirect call it displays the
 view for the function add, i.e. the add.ctp (which doesnt exists),
 but I want it to go back to chartofaccounts where the form is, and
 then display the errors there.

 On Feb 2, 9:30 pm, brian bally.z...@gmail.com wrote:
 You don't need to redirect. When you do so, the information stored in
 $validationErrors is lost because you're making a new request. If you
 remove the redirect() call, Cake should simply re-display the form.
 Then if all is working well, FormHelper will take care of printing the
 errors for you.

 On Mon, Feb 2, 2009 at 3:23 PM, Mickiii michael.la...@gmail.com wrote:

  Hi,

  This is probably simple, but I can't find any specifics on it.

  I have a controller called ledger_controller, which uses two models:
  Ledgeraccount and Ledgertransaction. Within this controller i have a
  function called chartofaccounts, which includes a form, with an action
  that leads to the ledger controller, but a function called add. I
  can save the data alright, and also validate it, but I can't get the
  error messages to show... why is that?

  Controller ledger:

 function add () {
 if(!empty($this-data)) {
 $this-Ledgeraccount-set($this-data);
 if($this-Ledgeraccount-validates()) {
 $this-Ledgeraccount-save($this-data, 
  false);
 $this-redirect('chartofaccounts');
 } else {
 $this-Session-setFlash('Venligt ret 
  fejlene herunder',
  'default', array('class'='bad'));
 $this-redirect('chartofaccounts');
 }
 }
 }

  Form in chartofaccounts.ctp

  ?=$form-create('Ledgeraccount', array('url' = '/ledger/add'));?

  ?
 echo $form-input('Ledgeraccount.number');
 echo $form-input('Ledgeraccount.name');
 echo $form-input('Ledgeraccount.type', array('options' = array(
 'header'='Header',
 'sum'='Sum',
 'profitloss'='Profit Loss',
 'balancesheet'='Balancesheet'
 )));
  ?

  ?=$form-end('Create');?

  If this is standard behaviour, then is there any way I can get the
  errormessages to show in the chartofaccounts view, without breaking
  the conventions too much?

  Thanks
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---