Re: Validate from within a model

2011-04-28 Thread euromark
but thats awfully wrong and dangerous
your primary validation should be in php (in the model)
js validation is just a nice little addon

On 28 Apr., 04:15, cake-learner sh.koiz...@gmail.com wrote:
 I always do validation with Jquery plugins not with cakephp function
 since the form function is limited.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Validate from within a model

2011-04-28 Thread func0der
Okay.

I'm doing it like this.

I'm havin a new file uploaded.
The file data, like mime type, name etc. will be saved in the db under
the file id.
I'm using that id as a filename for the files in my filesystem.
So i need to first create a db record to use the id.

Afterwards i'm trying to save the file.
If for example the folder for the upload is not writable or i don't
have the permission or any other case i can't figure out now happens,
then i want to cancel the upload and delete the db record so i won't
have 2 or more of the same file in the database.

This user is getting an error message that something fails during the
file upload and also i want to let the users know what they are
supposed to do next.

This is my intention.

And i would never validate file uploads with javascripts because of 2
reasons:
First, i don't know how
Second, i know enough to know that this kind of validation wouldn't be
save enough ^^

Nothing against you, but js alone isn't the key.

On 27 Apr., 23:54, Miles J mileswjohn...@gmail.com wrote:
 You dont need to use validates(), just set an error manually.

 $this-invalidate('fields', 'Error message.');

 Also, your approach is still wrong IMO. You should be doing all error
 checking before any save functionality is triggered. In what scenario
 will the image NOT copy/transfer? I have yet to ever run into that
 problem.

 On Apr 27, 12:31 pm, func0der funco...@live.com wrote:

  okay...i think i got it.

  It is part of the MVC pattern, isn't it?

  The model is NOT connected to the view or the helpers. These two are
  getting their data or the invalid error messages by the controller.

  Am i right here?

  On 27 Apr., 21:00, func0der funco...@live.com wrote:

   I can re-save and delete, so why i shouldn't be able to revalidate?

   The error message is also in the validationErrors variable but while
   the output of the form there is no error message.
   But why?

   On 27 Apr., 20:38, Miles J mileswjohn...@gmail.com wrote:

You can't validates() something after the model save has already
happened. Use a behavior for validation or use my plugin.

   https://github.com/milesj/cake-uploader

And an example model on how to use it.

   https://github.com/milesj/cake-uploader/blob/master/tests/models/uplo...

On Apr 27, 11:18 am, func0der funco...@live.com wrote:

 Hey guys,

 i'm having a file upload here.
 I'm using afterSave to place the uploaded file in the filesystem.

         function afterSave($created){
                 //get the entry id
                 $this-data['DataFile']['id'] = $this-getInsertId();
                 if(!$this-saveDataFile($this-data)){
                         $this-delete($this-data['DataFile']['id']);
                         $this-data['DataFile']['data_file'] = 
 array();
                         $this-validates();
                 }
         }

 saveDataFile is a function which tries to places the uploaded file
 in the file system and returns false in case of copy fails.

 If the copy should fail i delete the record from the database and set
 the data_file index which normally cotains the uploaded file
 information to an empty array. This is because i want the validation
 to fail so the file upload field gets an error message while
 rendering.

 The problem now is that the upload form does NOT! contain the
 validation error message for that particular field.

 Do you know what i am doing wrong?

 Greetings
 func0der

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Validate from within a model

2011-04-28 Thread Miles J
Why don't you just validate that the destination folder exists and is
writable?

On Apr 28, 2:57 am, func0der funco...@live.com wrote:
 Okay.

 I'm doing it like this.

 I'm havin a new file uploaded.
 The file data, like mime type, name etc. will be saved in the db under
 the file id.
 I'm using that id as a filename for the files in my filesystem.
 So i need to first create a db record to use the id.

 Afterwards i'm trying to save the file.
 If for example the folder for the upload is not writable or i don't
 have the permission or any other case i can't figure out now happens,
 then i want to cancel the upload and delete the db record so i won't
 have 2 or more of the same file in the database.

 This user is getting an error message that something fails during the
 file upload and also i want to let the users know what they are
 supposed to do next.

 This is my intention.

 And i would never validate file uploads with javascripts because of 2
 reasons:
 First, i don't know how
 Second, i know enough to know that this kind of validation wouldn't be
 save enough ^^

 Nothing against you, but js alone isn't the key.

 On 27 Apr., 23:54, Miles J mileswjohn...@gmail.com wrote:







  You dont need to use validates(), just set an error manually.

  $this-invalidate('fields', 'Error message.');

  Also, your approach is still wrong IMO. You should be doing all error
  checking before any save functionality is triggered. In what scenario
  will the image NOT copy/transfer? I have yet to ever run into that
  problem.

  On Apr 27, 12:31 pm, func0der funco...@live.com wrote:

   okay...i think i got it.

   It is part of the MVC pattern, isn't it?

   The model is NOT connected to the view or the helpers. These two are
   getting their data or the invalid error messages by the controller.

   Am i right here?

   On 27 Apr., 21:00, func0der funco...@live.com wrote:

I can re-save and delete, so why i shouldn't be able to revalidate?

The error message is also in the validationErrors variable but while
the output of the form there is no error message.
But why?

On 27 Apr., 20:38, Miles J mileswjohn...@gmail.com wrote:

 You can't validates() something after the model save has already
 happened. Use a behavior for validation or use my plugin.

https://github.com/milesj/cake-uploader

 And an example model on how to use it.

https://github.com/milesj/cake-uploader/blob/master/tests/models/uplo...

 On Apr 27, 11:18 am, func0der funco...@live.com wrote:

  Hey guys,

  i'm having a file upload here.
  I'm using afterSave to place the uploaded file in the filesystem.

          function afterSave($created){
                  //get the entry id
                  $this-data['DataFile']['id'] = 
  $this-getInsertId();
                  if(!$this-saveDataFile($this-data)){
                          
  $this-delete($this-data['DataFile']['id']);
                          $this-data['DataFile']['data_file'] = 
  array();
                          $this-validates();
                  }
          }

  saveDataFile is a function which tries to places the uploaded file
  in the file system and returns false in case of copy fails.

  If the copy should fail i delete the record from the database and 
  set
  the data_file index which normally cotains the uploaded file
  information to an empty array. This is because i want the validation
  to fail so the file upload field gets an error message while
  rendering.

  The problem now is that the upload form does NOT! contain the
  validation error message for that particular field.

  Do you know what i am doing wrong?

  Greetings
  func0der

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Validate from within a model

2011-04-28 Thread func0der
Can you explain that a bit more precise.

On Apr 28, 7:59 pm, Miles J mileswjohn...@gmail.com wrote:
 Why don't you just validate that the destination folder exists and is
 writable?

 On Apr 28, 2:57 am, func0der funco...@live.com wrote:







  Okay.

  I'm doing it like this.

  I'm havin a new file uploaded.
  The file data, like mime type, name etc. will be saved in the db under
  the file id.
  I'm using that id as a filename for the files in my filesystem.
  So i need to first create a db record to use the id.

  Afterwards i'm trying to save the file.
  If for example the folder for the upload is not writable or i don't
  have the permission or any other case i can't figure out now happens,
  then i want to cancel the upload and delete the db record so i won't
  have 2 or more of the same file in the database.

  This user is getting an error message that something fails during the
  file upload and also i want to let the users know what they are
  supposed to do next.

  This is my intention.

  And i would never validate file uploads with javascripts because of 2
  reasons:
  First, i don't know how
  Second, i know enough to know that this kind of validation wouldn't be
  save enough ^^

  Nothing against you, but js alone isn't the key.

  On 27 Apr., 23:54, Miles J mileswjohn...@gmail.com wrote:

   You dont need to use validates(), just set an error manually.

   $this-invalidate('fields', 'Error message.');

   Also, your approach is still wrong IMO. You should be doing all error
   checking before any save functionality is triggered. In what scenario
   will the image NOT copy/transfer? I have yet to ever run into that
   problem.

   On Apr 27, 12:31 pm, func0der funco...@live.com wrote:

okay...i think i got it.

It is part of the MVC pattern, isn't it?

The model is NOT connected to the view or the helpers. These two are
getting their data or the invalid error messages by the controller.

Am i right here?

On 27 Apr., 21:00, func0der funco...@live.com wrote:

 I can re-save and delete, so why i shouldn't be able to revalidate?

 The error message is also in the validationErrors variable but while
 the output of the form there is no error message.
 But why?

 On 27 Apr., 20:38, Miles J mileswjohn...@gmail.com wrote:

  You can't validates() something after the model save has already
  happened. Use a behavior for validation or use my plugin.

 https://github.com/milesj/cake-uploader

  And an example model on how to use it.

 https://github.com/milesj/cake-uploader/blob/master/tests/models/uplo...

  On Apr 27, 11:18 am, func0der funco...@live.com wrote:

   Hey guys,

   i'm having a file upload here.
   I'm using afterSave to place the uploaded file in the 
   filesystem.

           function afterSave($created){
                   //get the entry id
                   $this-data['DataFile']['id'] = 
   $this-getInsertId();
                   if(!$this-saveDataFile($this-data)){
                           
   $this-delete($this-data['DataFile']['id']);
                           $this-data['DataFile']['data_file'] = 
   array();
                           $this-validates();
                   }
           }

   saveDataFile is a function which tries to places the uploaded 
   file
   in the file system and returns false in case of copy fails.

   If the copy should fail i delete the record from the database and 
   set
   the data_file index which normally cotains the uploaded file
   information to an empty array. This is because i want the 
   validation
   to fail so the file upload field gets an error message while
   rendering.

   The problem now is that the upload form does NOT! contain the
   validation error message for that particular field.

   Do you know what i am doing wrong?

   Greetings
   func0der

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Validate from within a model

2011-04-28 Thread cricket
On Thu, Apr 28, 2011 at 2:17 PM, func0der funco...@live.com wrote:
 Can you explain that a bit more precise.

http://php.net/manual/en/function.is-dir.php
http://www.php.net/manual/en/function.is-writable.php

I usually handle uploads on the controller/component side. Save your
model record, get the new ID, save the file, update the record. You
can leave out the initial save in some cases but you said that you're
using the id for the file name so you'd need 2 saves.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Validate from within a model

2011-04-28 Thread Miles J
You can also create the folders and make the writable before hand,
that way the file will always upload.

On Apr 28, 12:55 pm, cricket zijn.digi...@gmail.com wrote:
 On Thu, Apr 28, 2011 at 2:17 PM, func0der funco...@live.com wrote:
  Can you explain that a bit more precise.

 http://php.net/manual/en/function.is-dir.phphttp://www.php.net/manual/en/function.is-writable.php

 I usually handle uploads on the controller/component side. Save your
 model record, get the new ID, save the file, update the record. You
 can leave out the initial save in some cases but you said that you're
 using the id for the file name so you'd need 2 saves.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Validate from within a model

2011-04-27 Thread Miles J
You can't validates() something after the model save has already
happened. Use a behavior for validation or use my plugin.

https://github.com/milesj/cake-uploader

And an example model on how to use it.

https://github.com/milesj/cake-uploader/blob/master/tests/models/upload.php

On Apr 27, 11:18 am, func0der funco...@live.com wrote:
 Hey guys,

 i'm having a file upload here.
 I'm using afterSave to place the uploaded file in the filesystem.

         function afterSave($created){
                 //get the entry id
                 $this-data['DataFile']['id'] = $this-getInsertId();
                 if(!$this-saveDataFile($this-data)){
                         $this-delete($this-data['DataFile']['id']);
                         $this-data['DataFile']['data_file'] = array();
                         $this-validates();
                 }
         }

 saveDataFile is a function which tries to places the uploaded file
 in the file system and returns false in case of copy fails.

 If the copy should fail i delete the record from the database and set
 the data_file index which normally cotains the uploaded file
 information to an empty array. This is because i want the validation
 to fail so the file upload field gets an error message while
 rendering.

 The problem now is that the upload form does NOT! contain the
 validation error message for that particular field.

 Do you know what i am doing wrong?

 Greetings
 func0der

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Validate from within a model

2011-04-27 Thread func0der
I can re-save and delete, so why i shouldn't be able to revalidate?

The error message is also in the validationErrors variable but while
the output of the form there is no error message.
But why?

On 27 Apr., 20:38, Miles J mileswjohn...@gmail.com wrote:
 You can't validates() something after the model save has already
 happened. Use a behavior for validation or use my plugin.

 https://github.com/milesj/cake-uploader

 And an example model on how to use it.

 https://github.com/milesj/cake-uploader/blob/master/tests/models/uplo...

 On Apr 27, 11:18 am, func0der funco...@live.com wrote:

  Hey guys,

  i'm having a file upload here.
  I'm using afterSave to place the uploaded file in the filesystem.

          function afterSave($created){
                  //get the entry id
                  $this-data['DataFile']['id'] = $this-getInsertId();
                  if(!$this-saveDataFile($this-data)){
                          $this-delete($this-data['DataFile']['id']);
                          $this-data['DataFile']['data_file'] = array();
                          $this-validates();
                  }
          }

  saveDataFile is a function which tries to places the uploaded file
  in the file system and returns false in case of copy fails.

  If the copy should fail i delete the record from the database and set
  the data_file index which normally cotains the uploaded file
  information to an empty array. This is because i want the validation
  to fail so the file upload field gets an error message while
  rendering.

  The problem now is that the upload form does NOT! contain the
  validation error message for that particular field.

  Do you know what i am doing wrong?

  Greetings
  func0der

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Validate from within a model

2011-04-27 Thread func0der
okay...i think i got it.

It is part of the MVC pattern, isn't it?

The model is NOT connected to the view or the helpers. These two are
getting their data or the invalid error messages by the controller.

Am i right here?

On 27 Apr., 21:00, func0der funco...@live.com wrote:
 I can re-save and delete, so why i shouldn't be able to revalidate?

 The error message is also in the validationErrors variable but while
 the output of the form there is no error message.
 But why?

 On 27 Apr., 20:38, Miles J mileswjohn...@gmail.com wrote:

  You can't validates() something after the model save has already
  happened. Use a behavior for validation or use my plugin.

 https://github.com/milesj/cake-uploader

  And an example model on how to use it.

 https://github.com/milesj/cake-uploader/blob/master/tests/models/uplo...

  On Apr 27, 11:18 am, func0der funco...@live.com wrote:

   Hey guys,

   i'm having a file upload here.
   I'm using afterSave to place the uploaded file in the filesystem.

           function afterSave($created){
                   //get the entry id
                   $this-data['DataFile']['id'] = $this-getInsertId();
                   if(!$this-saveDataFile($this-data)){
                           $this-delete($this-data['DataFile']['id']);
                           $this-data['DataFile']['data_file'] = array();
                           $this-validates();
                   }
           }

   saveDataFile is a function which tries to places the uploaded file
   in the file system and returns false in case of copy fails.

   If the copy should fail i delete the record from the database and set
   the data_file index which normally cotains the uploaded file
   information to an empty array. This is because i want the validation
   to fail so the file upload field gets an error message while
   rendering.

   The problem now is that the upload form does NOT! contain the
   validation error message for that particular field.

   Do you know what i am doing wrong?

   Greetings
   func0der

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Validate from within a model

2011-04-27 Thread Miles J
You dont need to use validates(), just set an error manually.

$this-invalidate('fields', 'Error message.');

Also, your approach is still wrong IMO. You should be doing all error
checking before any save functionality is triggered. In what scenario
will the image NOT copy/transfer? I have yet to ever run into that
problem.

On Apr 27, 12:31 pm, func0der funco...@live.com wrote:
 okay...i think i got it.

 It is part of the MVC pattern, isn't it?

 The model is NOT connected to the view or the helpers. These two are
 getting their data or the invalid error messages by the controller.

 Am i right here?

 On 27 Apr., 21:00, func0der funco...@live.com wrote:







  I can re-save and delete, so why i shouldn't be able to revalidate?

  The error message is also in the validationErrors variable but while
  the output of the form there is no error message.
  But why?

  On 27 Apr., 20:38, Miles J mileswjohn...@gmail.com wrote:

   You can't validates() something after the model save has already
   happened. Use a behavior for validation or use my plugin.

  https://github.com/milesj/cake-uploader

   And an example model on how to use it.

  https://github.com/milesj/cake-uploader/blob/master/tests/models/uplo...

   On Apr 27, 11:18 am, func0der funco...@live.com wrote:

Hey guys,

i'm having a file upload here.
I'm using afterSave to place the uploaded file in the filesystem.

        function afterSave($created){
                //get the entry id
                $this-data['DataFile']['id'] = $this-getInsertId();
                if(!$this-saveDataFile($this-data)){
                        $this-delete($this-data['DataFile']['id']);
                        $this-data['DataFile']['data_file'] = array();
                        $this-validates();
                }
        }

saveDataFile is a function which tries to places the uploaded file
in the file system and returns false in case of copy fails.

If the copy should fail i delete the record from the database and set
the data_file index which normally cotains the uploaded file
information to an empty array. This is because i want the validation
to fail so the file upload field gets an error message while
rendering.

The problem now is that the upload form does NOT! contain the
validation error message for that particular field.

Do you know what i am doing wrong?

Greetings
func0der

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Validate from within a model

2011-04-27 Thread cake-learner
I always do validation with Jquery plugins not with cakephp function
since the form function is limited.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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