Detecting file size overflow (POST Content-Length of 30980857 bytes exceeds the limit of 2097152 bytes)

2015-04-13 Thread Willem
When uploading a file bigger then the post_max_size setting in php.ini the 
$_FILES global will be empty. CakePHP does not give an error and saves the 
rest of the data (as the $this->data still has data for the rest of the 
model) 

How can i catch this in CakePHP?


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: [Cake 2.6.3] Cake's FileUpload Validation not working; what is wrong?

2015-04-13 Thread Willem
It worked thanks!

On Monday, April 13, 2015 at 6:18:36 PM UTC+2, John Andersen wrote:
>
> The validation in your model points to a field named "image", but the view 
> you have points to a field named "submittedFile" :)
> Which is the correct one?
> Enjoy, John
>
> On Monday, 13 April 2015 11:17:13 UTC+3, Willem wrote:
>>
>> I have a model "Attachment" which Belongs to another model (hasMany 
>> Attachment). 
>>
>> In model Attachment I put a validator (from the Cake helpbook) to check 
>> against filetypes. After saveAssociated i would expect an error if uploaded 
>> a .txt file, but the model is save successfully?
>>
>> *Add.ctp* 
>>
>> for($i=0;$i<1;$i++)
>> {
>> ?>
>> 
>> > echo $this->Form->file('Attachment.'.$i.'.submittedfile');
>> ?>
>> 
>> > }
>>
>>
>>
>> *Attachment model:*
>>
>> > App::uses('AppModel', 'Model');
>>
>> class Attachment extends AppModel {
>>
>> public $belongsTo = 'CollectionRequest';
>>
>> public $validate = array(
>> 'image' => array(
>> 'rule' => array(
>> 'extension',
>> array('gif', 'jpeg', 'png', 'jpg')
>> ),
>> 'message' => 'Please supply a valid image.'
>> )
>> );
>>
>>
>> public function beforeSave($options = array()) {
>>
>> parent::beforeSave($options);
>> }
>>
>> public function beforeValidate($options = array()) {
>>
>> // ignore empty file - causes issues with form validation when 
>> file is empty and optional
>> if (!empty($this->data[$this->alias]['error']) &&
>> $this->data[$this->alias]['error']==4 &&
>> $this->data[$this->alias]['size']==0) {
>> unset($this->data[$this->alias]);
>> }
>>
>>
>> parent::beforeValidate($options);
>> }
>>
>> }
>>
>>
>> ?>
>>
>> *Controller*
>>
>>  if ($this->CollectionRequest->saveAssociated($this->request->data)) {
>> // All good
>> 
>> $this->Session->setFlash(__('CollectionRequest saved'));
>> return $this->redirect(array('action' => 'index'));
>> }
>>
>>
>> thanks
>>
>>
>>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: [Cake 2.6.3] Cake's FileUpload Validation not working; what is wrong?

2015-04-13 Thread Willem
Hi,

thanks, will try this ASAP. I got it mixed up thiking it was an 
alias/name/labe as in multiple validations per field. :-S





On Monday, April 13, 2015 at 6:18:36 PM UTC+2, John Andersen wrote:
>
> The validation in your model points to a field named "image", but the view 
> you have points to a field named "submittedFile" :)
> Which is the correct one?
> Enjoy, John
>
> On Monday, 13 April 2015 11:17:13 UTC+3, Willem wrote:
>>
>> I have a model "Attachment" which Belongs to another model (hasMany 
>> Attachment). 
>>
>> In model Attachment I put a validator (from the Cake helpbook) to check 
>> against filetypes. After saveAssociated i would expect an error if uploaded 
>> a .txt file, but the model is save successfully?
>>
>> *Add.ctp* 
>>
>> for($i=0;$i<1;$i++)
>> {
>> ?>
>> 
>> > echo $this->Form->file('Attachment.'.$i.'.submittedfile');
>> ?>
>> 
>> > }
>>
>>
>>
>> *Attachment model:*
>>
>> > App::uses('AppModel', 'Model');
>>
>> class Attachment extends AppModel {
>>
>> public $belongsTo = 'CollectionRequest';
>>
>> public $validate = array(
>> 'image' => array(
>> 'rule' => array(
>> 'extension',
>> array('gif', 'jpeg', 'png', 'jpg')
>> ),
>> 'message' => 'Please supply a valid image.'
>> )
>> );
>>
>>
>> public function beforeSave($options = array()) {
>>
>> parent::beforeSave($options);
>> }
>>
>> public function beforeValidate($options = array()) {
>>
>> // ignore empty file - causes issues with form validation when 
>> file is empty and optional
>> if (!empty($this->data[$this->alias]['error']) &&
>> $this->data[$this->alias]['error']==4 &&
>> $this->data[$this->alias]['size']==0) {
>> unset($this->data[$this->alias]);
>> }
>>
>>
>> parent::beforeValidate($options);
>> }
>>
>> }
>>
>>
>> ?>
>>
>> *Controller*
>>
>>  if ($this->CollectionRequest->saveAssociated($this->request->data)) {
>> // All good
>> 
>> $this->Session->setFlash(__('CollectionRequest saved'));
>> return $this->redirect(array('action' => 'index'));
>> }
>>
>>
>> thanks
>>
>>
>>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: [Cake 2.6.3] Cake's FileUpload Validation not working; what is wrong?

2015-04-13 Thread John Andersen
The validation in your model points to a field named "image", but the view 
you have points to a field named "submittedFile" :)
Which is the correct one?
Enjoy, John

On Monday, 13 April 2015 11:17:13 UTC+3, Willem wrote:
>
> I have a model "Attachment" which Belongs to another model (hasMany 
> Attachment). 
>
> In model Attachment I put a validator (from the Cake helpbook) to check 
> against filetypes. After saveAssociated i would expect an error if uploaded 
> a .txt file, but the model is save successfully?
>
> *Add.ctp* 
>
> for($i=0;$i<1;$i++)
> {
> ?>
> 
>  echo $this->Form->file('Attachment.'.$i.'.submittedfile');
> ?>
> 
>  }
>
>
>
> *Attachment model:*
>
>  App::uses('AppModel', 'Model');
>
> class Attachment extends AppModel {
>
> public $belongsTo = 'CollectionRequest';
>
> public $validate = array(
> 'image' => array(
> 'rule' => array(
> 'extension',
> array('gif', 'jpeg', 'png', 'jpg')
> ),
> 'message' => 'Please supply a valid image.'
> )
> );
>
>
> public function beforeSave($options = array()) {
>
> parent::beforeSave($options);
> }
>
> public function beforeValidate($options = array()) {
>
> // ignore empty file - causes issues with form validation when 
> file is empty and optional
> if (!empty($this->data[$this->alias]['error']) &&
> $this->data[$this->alias]['error']==4 &&
> $this->data[$this->alias]['size']==0) {
> unset($this->data[$this->alias]);
> }
>
>
> parent::beforeValidate($options);
> }
>
> }
>
>
> ?>
>
> *Controller*
>
>  if ($this->CollectionRequest->saveAssociated($this->request->data)) {
> // All good
> 
> $this->Session->setFlash(__('CollectionRequest saved'));
> return $this->redirect(array('action' => 'index'));
> }
>
>
> thanks
>
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to set class on form template node with {{attrs}} defined?

2015-04-13 Thread Dieter Gribnitz
I had another look at the code and found that this seems to be a tough nut 
to crack.
Since some templates are called directly from the form helper methods and 
some attributes get set inside the widgets it is a bit of a problem setting 
a default class via a single method or in a single place.
The reason I needed to set a class was for jquery to execute operations on 
the input elements.
I have decided to create a custom html attribute instead called "render" 
and invoke it like so: $('[render="wysiwyg"]').;
Now I can just extend the form helper's input function and add the required 
render method to the options from my field configuration registry.
Would be great if we were able to set default or primary attribute values 
via the theme but I fear the template method might make this near 
impossible right now.

My problem is resolved but if there is a better way of doing this, please 
let me know.
Thanks.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


[Cake 2.6.3] Cake's FileUpload Validation not working; what is wrong?

2015-04-13 Thread Willem
I have a model "Attachment" which Belongs to another model (hasMany 
Attachment). 

In model Attachment I put a validator (from the Cake helpbook) to check 
against filetypes. After saveAssociated i would expect an error if uploaded 
a .txt file, but the model is save successfully?

*Add.ctp* 

for($i=0;$i<1;$i++)
{
?>

Form->file('Attachment.'.$i.'.submittedfile');
?>

 array(
'rule' => array(
'extension',
array('gif', 'jpeg', 'png', 'jpg')
),
'message' => 'Please supply a valid image.'
)
);


public function beforeSave($options = array()) {

parent::beforeSave($options);
}

public function beforeValidate($options = array()) {

// ignore empty file - causes issues with form validation when file 
is empty and optional
if (!empty($this->data[$this->alias]['error']) &&
$this->data[$this->alias]['error']==4 &&
$this->data[$this->alias]['size']==0) {
unset($this->data[$this->alias]);
}


parent::beforeValidate($options);
}

}


?>

*Controller*

 if ($this->CollectionRequest->saveAssociated($this->request->data)) {
// All good

$this->Session->setFlash(__('CollectionRequest saved'));
return $this->redirect(array('action' => 'index'));
}


thanks


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.