| View previous topic :: View next topic |
| Author |
Message |
ozmenm
Joined: 11 Aug 2008 Posts: 4
|
Posted: Mon Aug 11, 2008 8:54 am Post subject: how can i set date element as required field? |
|
|
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Mon Aug 11, 2008 9:14 am Post subject: |
|
|
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 |
|
 |
ozmenm
Joined: 11 Aug 2008 Posts: 4
|
Posted: Mon Aug 11, 2008 9:51 am Post subject: |
|
|
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Mon Aug 11, 2008 10:03 am Post subject: |
|
|
| 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 |
|
 |
ozmenm
Joined: 11 Aug 2008 Posts: 4
|
Posted: Mon Aug 11, 2008 10:17 am Post subject: |
|
|
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Mon Aug 11, 2008 1:08 pm Post subject: |
|
|
| 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 |
|
 |
ozmenm
Joined: 11 Aug 2008 Posts: 4
|
Posted: Mon Aug 11, 2008 2:31 pm Post subject: |
|
|
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 |
|
 |
|