PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
how can i set date element as required field?

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> HTML
View previous topic :: View next topic  
Author Message
ozmenm



Joined: 11 Aug 2008
Posts: 4

PostPosted: Mon Aug 11, 2008 8:54 am    Post subject: how can i set date element as required field? Reply with quote

hi,

i create a form with html_quickform, i add date field which name is dcdate.
i want to set this field as required field.
* mark appears in my form view, but its not work..


here is my code;
$form->addElement('date', 'dc_date', 'Date:', array("minYear"=>1900, "format"=>"d-F-Y" ,"addEmptyOption"=>true));
$form->addRule(dc_date, "Date", 'required', null, 'client');


how can i set date element as required field?

thanks in advance
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 998

PostPosted: Mon Aug 11, 2008 9:14 am    Post subject: Reply with quote

The following line generates a notice:

Code:

$form->addRule(dc_date, "Date", 'required', null, 'client');


For date elements, you need to use addGroupRule() because date elements are groups of multiple elements internally.
Back to top
View user's profile Send private message
ozmenm



Joined: 11 Aug 2008
Posts: 4

PostPosted: Mon Aug 11, 2008 9:51 am    Post subject: Reply with quote

thank you,

but i couldnt find the group name of date element.

i tried this line;
$form1->addGroupRule("dc_date","Date", 'required', "null", 3);

it doesnt work..
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 998

PostPosted: Mon Aug 11, 2008 10:03 am    Post subject: Reply with quote

The group name is the element name of the date element, i.e. 'dc_date' is right. But are you sure about $form1? In your first post it was $form. And 'null' is wrong, it needs to be simply null, without the quotes (it is a PHP constant).
Back to top
View user's profile Send private message
ozmenm



Joined: 11 Aug 2008
Posts: 4

PostPosted: Mon Aug 11, 2008 10:17 am    Post subject: Reply with quote

yes sorry,

my form name is form1.
both of my date element and addgrouprule form is same.
and i also tried NULL without quotes.. but it doesnt work..

i use html_quickform with PHP5, should i use html_quickform2?
is it important? i see it today and i dont even know its usage..
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 998

PostPosted: Mon Aug 11, 2008 1:08 pm    Post subject: Reply with quote

ozmenm wrote:
my form name is form1.
both of my date element and addgrouprule form is same.
and i also tried NULL without quotes.. but it doesnt work..


What does "it doesn't work" mean? What do you expect? Remember that the date element has no empty state by default, i.e. e.g. you'll all days from 1 to 31, but no empty option that allows to select no date. And therefore, the element always is valid. Do you have empty options added yourself?

ozmenm wrote:
i use html_quickform with PHP5, should i use html_quickform2?
is it important? i see it today and i dont even know its usage..


QF2 is at an early stage, I'd stick with the current QF version for now.
Back to top
View user's profile Send private message
ozmenm



Joined: 11 Aug 2008
Posts: 4

PostPosted: Mon Aug 11, 2008 2:31 pm    Post subject: Reply with quote

you are right,

a true addEmptyOption gaves me 0000-00-00 if user was not select value. if i set false, date returns 1900-00-00 as an empty value.. i dont want this situation..

anyway..thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> HTML All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software