Home > Archive > PHP Pear > June 2006 > QuickForms: error in client validation uploading a file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
QuickForms: error in client validation uploading a file
|
|
|
| Hi,
I have a form with two rules like these:
------------------------------------------------------------------------
$this->file =& $this->addElement('file', 'userfile', 'Imagen:(max:1MB)',
array('size'=>50, 'maxlength'=>100));
$this->file2 =& $this->addElement('file', 'userfile2',
'Documento:(max:2MB)', array('size'=>50, 'maxlength'=>100));
------------------------------------------------------------------------
and two rules:
------------------------------------------------------------------------
$this->addRule('userfile', 'El fichero de imagen es demasiado grande.',
'maxfilesize', 1048576,'client');
$this->addRule('userfile2', 'El fichero es demasiado grande.',
'maxfilesize', 2097152,'client');
------------------------------------------------------------------------
that generates this piece of java script:
------------------------------------------------------------------------
86 value = frm.elements['userfile'].value;
87 if (value != '' && !_ruleCheckMaxFileSize(value, '1048576') && !errFlag['userfile']) {
88 errFlag['userfile'] = true;
89 _qfMsg = _qfMsg + '\n - El fichero de imagen es demasiado grande.';
90 }
91
92 value = frm.elements['userfile2'].value;
93 if (value != '' && !_ruleCheckMaxFileSize(value, '2097152') && !errFlag['userfile2']) {
94 errFlag['userfile2'] = true;
95 _qfMsg = _qfMsg + '\n - El fichero es demasiado grande.';
96 }
------------------------------------------------------------------------
and at last the browser get me this error message:
------------------------------------------------------------------------
Error: _ruleCheckMaxFileSize is not defined
Source File: ...
Line: 93
------------------------------------------------------------------------
(at the second call!!) and the client validation is not done at all.
Anyone with any ideas? I didn't find anything out there.
Thanks.
Toni.
| |
| rssaddict 2006-06-29, 2:23 pm |
| quote: Originally posted by Toni
Hi,
I have a form with two rules like these:
------------------------------------------------------------------------
$this->file =& $this->addElement('file', 'userfile', 'Imagen:(max:1MB)',
array('size'=>50, 'maxlength'=>100));
$this->file2 =& $this->addElement('file', 'userfile2',
'Documento:(max:2MB)', array('size'=>50, 'maxlength'=>100));
------------------------------------------------------------------------
and two rules:
------------------------------------------------------------------------
$this->addRule('userfile', 'El fichero de imagen es demasiado grande.',
'maxfilesize', 1048576,'client');
$this->addRule('userfile2', 'El fichero es demasiado grande.',
'maxfilesize', 2097152,'client');
------------------------------------------------------------------------
that generates this piece of java script:
------------------------------------------------------------------------
86 value = frm.elements['userfile'].value;
87 if (value != '' && !_ruleCheckMaxFileSize(value, '1048576') && !errFlag['userfile']) {
88 errFlag['userfile'] = true;
89 _qfMsg = _qfMsg + '\n - El fichero de imagen es demasiado grande.';
90 }
91
92 value = frm.elements['userfile2'].value;
93 if (value != '' && !_ruleCheckMaxFileSize(value, '2097152') && !errFlag['userfile2']) {
94 errFlag['userfile2'] = true;
95 _qfMsg = _qfMsg + '\n - El fichero es demasiado grande.';
96 }
------------------------------------------------------------------------
and at last the browser get me this error message:
------------------------------------------------------------------------
Error: _ruleCheckMaxFileSize is not defined
Source File: ...
Line: 93
------------------------------------------------------------------------
(at the second call!!) and the client validation is not done at all.
Anyone with any ideas? I didn't find anything out there.
Thanks.
Toni.
This is simply a bug with the client-side validation of file elements in HTML_Quickform. The bug was reported here: http://pear.php.net/bugs/bug.php?id=134
The problem is that _ruleCheckMaxFileSize is a PHP function (not a javascript function). However, the recommendation from the PEAR site is to simply not use client-side validation for file elements.
Hope that helps. |
|
|
|
|