QuickForm (QF): trouble with a group of 'file' elements and group rules
| From: | jam at zoidtechnologies dot com | Date: | Wed, 06 Dec 2006 00:35:01 +0000 |
| Subject: | QuickForm (QF): trouble with a group of 'file' elements and group rules | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-25978@lists.php.net to get a copy of this message | ||
greetings,
*please* CC me on any replies as I am not currently subscribed to the
pear-general list. thank you.
I have the following bit of code (with some things removed) that I am
attempting to get working:
-- begin code ---
$form = new HTML_QuickForm("foo", "post", null, null, array("mimetype"
=> "multipart/form-data"));
$form->addElement("header", "header", "example header");
$images = array();
for ($i = 0; $i < 10; $i++)
{
$images[] = &HTML_QuickForm::createElement("file", "", "Image
{$i}");
}
$form->addGroup($images, "images", "Images", "<br />");
$form->addGroupRule("images", "File size must be less than 512kilobytes",
"maxfilesize", 512000);
$form->addGroupRule("images", "File name must be *.jpg or *.jpeg",
"filename", "/\.[jpg|jpeg]$/");
$form->addGroupRule("images", "File must be of type jpeg image",
"mimetype", array("image/jpeg"));
$form->addGroupRule("images", "File must be uploaded",
"uploadedfile");
--- end code ---
I expect the following to happen against the 'images' group given the rules
I've set up:
- the files must be of mime type image/jpeg
- the files must be less than 512000 bytes in length
- the files must end with jpg or jpeg
I read an article (http://www.midnighthax.com/quickform.php) that told me to
use "True" as the last argument in the process() method call because file
elements are involved. I've done that. now, at least, I get an array of
files, however QF does not error when I upload a gif image instead of a jpg.
even if I have the regexp set up incorrectly, the mimetype check should
cover me, but it does not. the code sails through to the processing method
I've set up without a hiccup :(
one of my revisions of this code tried to add an element rule for the 10
elements inside the foreach. this did not work, so I tried it with a
grouprule() call instead, and I'm having similar troubles with rule
enforcement. I've decided to ask the list before I go down another dead end
attempt at a solution.
note that during the processing phase, it looks like I'm getting appropriate
information from QF.
are element names such as "image[0]" and "image[1]" for the file elements
common in this sort of application considering I am using groups? will that
cause QF to have trouble enforcing the GroupRules?
any assistance with this issue is appreciated.
again, please CC me on any replies as I am not currently subscribed to the
pear-general list. thank you.
regards,
J