PEAR Packages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPEAR Packages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 2nd, 2007, 08:24 AM
tallberg tallberg is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 14 tallberg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 15 m 8 sec
Reputation Power: 0
Adding rules to select elements.

Hi

I would like to validate a select element add with html_quick form.

The first entry of the select should be either a blank string or some text stating 'select a collection'

I cant see how I would apply a rule to insure an option is selected.


Code:
$form->addRule('collection', 'Please provide a collection', 'required', null, 'client');	



The required rule would be: if the select option = 'select a collection' dont validate

Last edited by tallberg : November 2nd, 2007 at 08:49 AM.

Reply With Quote
  #2  
Old November 2nd, 2007, 08:50 AM
tallberg tallberg is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 14 tallberg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 15 m 8 sec
Reputation Power: 0
Another one.

How do you add a rule to the file element to enforce file type?

Thanks

Reply With Quote
  #3  
Old November 2nd, 2007, 10:09 AM
wiesemann wiesemann is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 152 wiesemann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 26 m 25 sec
Reputation Power: 2
The 'required' rule compares the selected values against '' (= empty string). Therefore, you just have to assign an empty string as the value to the items that you identify as not valid. Otherwise, you'll need a custom rule.

For mime type checks, you can use the 'mimetype' rule:
http://pear.php.net/manual/en/package.html.html-quickform.intro-validation.php

Reply With Quote
  #4  
Old November 2nd, 2007, 11:34 AM
tallberg tallberg is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 14 tallberg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 15 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by wiesemann
The 'required' rule compares the selected values against '' (= empty string). Therefore, you just have to assign an empty string as the value to the items that you identify as not valid. Otherwise, you'll need a custom rule.

For mime type checks, you can use the 'mimetype' rule:
http://pear.php.net/manual/en/package.html.html-quickform.intro-validation.php


Thanks for the reply im new to this pear stuff.

here is what i got for the jpg validation. Not working

$jpgArray = Array('0' => 'image/jpe', '1' => 'image/jpeg', '2' => 'image/jpg');

$form->addRule('file', 'File must be jpg', 'mimetype', $jpgArray, 'server');

And

for the select element i take your point about required.

this is my select element

$form->addElement('select', 'collection', 'Collection', $collection_options, 'class=selectbox');

the first value of the $collection_options array is 0 => ' ' which is blank string but the value is 0 so the form validates which not what i want.

thank again.

Reply With Quote
  #5  
Old November 2nd, 2007, 11:58 AM
wiesemann wiesemann is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 152 wiesemann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 26 m 25 sec
Reputation Power: 2
$form->addRule('file'

should be

$form->addRule('collection'

The first parameter of addRule() is the name of an element.

Reply With Quote
  #6  
Old November 2nd, 2007, 12:11 PM
tallberg tallberg is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 14 tallberg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 15 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by wiesemann
$form->addRule('file'

should be

$form->addRule('collection'

The first parameter of addRule() is the name of an element.


I get that. "file" is the name i gave to the file element. collection is the select element.

Ive sort out the select.

still cant get file working. Ive changed the name to see if that helps and it made not difference. Here it is.

Code:
$jpgArray = Array('0' => 'image/jpe', '1' => 'image/jpeg', '2' => 'image/jpg');
$form->addRule('uploadjpg', 'File must be jpg', 'mimetype', $jpgArray, 'server');

Last edited by tallberg : November 2nd, 2007 at 12:19 PM.

Reply With Quote
  #7  
Old November 2nd, 2007, 01:57 PM
wiesemann wiesemann is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 152 wiesemann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 26 m 25 sec
Reputation Power: 2
Okay, let's see:

If you have only numeric values in your select element, you can use the 'nonzero' rule which doesn't validate on 0. You should be able to combine this rule with the 'required' rule to get the star symbol.

About the mime type problem: The code looks right, but maybe the detected mime type differs from the specified types. You can check this by outputting the $_FILES array in your script. The key 'type' holds the mime type that QF checks in the 'mimetype' rule.

Reply With Quote
  #8  
Old November 5th, 2007, 05:19 AM
tallberg tallberg is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 14 tallberg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 15 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by wiesemann
Okay, let's see:

If you have only numeric values in your select element, you can use the 'nonzero' rule which doesn't validate on 0. You should be able to combine this rule with the 'required' rule to get the star symbol.

About the mime type problem: The code looks right, but maybe the detected mime type differs from the specified types. You can check this by outputting the $_FILES array in your script. The key 'type' holds the mime type that QF checks in the 'mimetype' rule.



Thank very much for your help.
I found a solution to my problem.

First line of the options array.
$photo_collection[''] = 'Select a collection';
There is no value so the form does not validate as needed.

Regarding the file element validation.
The element:
$form->addElement('file', 'uploaded_file', "<span class='fieldtitle'>JPG file:</span>", 'class=fileupload');

The rules:

$form->addRule('uploaded_file','Please upload a file','uploadedfile');

$form->addRule('uploaded_file','Please upload a JPG file', 'mimetype', Array('0' => 'image/jpe', '1' => 'image/jpeg', '2' => 'image/jpg'));

Hopefully the end.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > Adding rules to select elements.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway