Home » HTML » HTML_QuickForm » Bug #8789
Cannot validate file with 'required' on the client side
Details
| Submitted | 2006-09-25 19:57 UTC |
|---|---|
| From | paweusz at wp dot pl |
| Status | Bogus |
| Package | HTML_QuickForm |
| PHP Version | 4.4.3 |
| OS | irrevelant |
| Roadmaps | (Not assigned) |
Comments
[2006-09-25 19:57 UTC] paweusz at wp dot pl
Description:
------------
Sometimes it is desired to check if the file is to be uploaded BEFORE 'submit' was hit. So i understand a similar bug was solved, but not thoroughly.
When you add a rule 'required' to field type 'file', it shows a notice 'array to string conversion' after file was uploaded. It isn't what we want, when we need to make user not forget to upload the file, so why not to change it? There is no other way to check if the file is to be uploaded on the client-side.
I'm not convinced if the to-string conversion is needed in this case. We could use well-known identity: '' == Array() == null (Solution 2). If the conversion IS needed, then we should repair it after solution 1.
Test script:
---------------
==== CAUSING ERROR ====
$form->addElement('file', 'file', 'file', array('class' => 'file'));
...
$form->addRule('file', 'you must upload a file', 'required', '', 'client');
-------------------------------------------
File: HTML/QuickForm/Rule.php ==
==== SOLUTION 1 ====
39: if (@(string)$value == '') {
==== SOLUTION 2 ====
39: if ($value == '') {
Expected result:
----------------
Error - "array to string conversion" notice.
After applying sol.1 or 2 - it will disappear
[2006-10-07 17:12 UTC] paweusz at wp dot pl
I really know that now I cannot use 'required' rule to
field type 'file' :) That is what this BUG report is
about.
Although, I THINK, that it should be available to use
'required' rule or something similar, because it would
make many people not to FORGET about submitting a file
(because many people fills other fields at first, and
forgets to fill the FILE field). I understand that it
wouldn't be sufficient, and I should also check
'uploadedfile' rule.
Another solution to this problem is adding relevant
javascript to 'uploaded' rule for testing if the field is
at least filled (and I understand, that it is not possible
to check if the string points to a valid file).