FormBuilder DatePickerField remove day dropdown, only have month and year

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
mvandiermen
Forum Members
Forum Members
Posts: 83
Joined: Mon Nov 03, 2008 1:28 pm

FormBuilder DatePickerField remove day dropdown, only have month and year

Post by mvandiermen »

Hello,

I was wondering how I can remove the day dropdown from the FormBuilder DatePickerField, as I only need to user to pick the month and year.
There is an option that says Date Format: j F Y, but does not seen to change anything



DatePickerField.class.php:

Code: Select all


<?php
/* 
   FormBuilder. Copyright (c) 2005-2006 Samuel Goldstein <sjg@cmsmodules.com>
   More info at http://dev.cmsmadesimple.org/projects/formbuilder
   
   A Module for CMS Made Simple, Copyright (c) 2006 by Ted Kulp (wishy@cmsmadesimple.org)
  This project's homepage is: http://www.cmsmadesimple.org
*/

class fbDatePickerField extends fbFieldBase {

	var $Months;
	
	function fbDatePickerField(&$form_ptr, &$params)
	{
        $this->fbFieldBase($form_ptr, $params);
        $mod = &$form_ptr->module_ptr;
		$this->Type = 'DatePickerField';
		$this->DisplayInForm = true;
		$this->ValidationTypes = array(
            $mod->Lang('validation_none')=>'none',
            );
        $this->Months = array(
            $mod->Lang('date_january')=>1,
            $mod->Lang('date_february')=>2,
            $mod->Lang('date_march')=>3,
            $mod->Lang('date_april')=>4,
            $mod->Lang('date_may')=>5,
            $mod->Lang('date_june')=>6,
            $mod->Lang('date_july')=>7,
            $mod->Lang('date_august')=>8,
            $mod->Lang('date_september')=>9,
            $mod->Lang('date_october')=>10,
            $mod->Lang('date_november')=>11,
            $mod->Lang('date_december')=>12);
    $this->hasMultipleFormComponents = true;
    $this->labelSubComponents = false;
	}


    function StatusInfo()
	{
      $mod = &$this->form_ptr->module_ptr;
      $today = getdate();
		return $mod->Lang("date_range",array($this->GetOption('start_year',($today['year']-10)) ,
         $this->GetOption('end_year',($today['year']+10)))).
         ($this->GetOption('default_year','-1')!=='-1'?' ('.$this->GetOption('default_year','-1').')':'');
	}


	function GetFieldInput($id, &$params, $returnid)
	{
		$mod = &$this->form_ptr->module_ptr;
       $today = getdate();
       $Days = array();
       for ($i=1;$i<32;$i++)
         {
         	$Days[$i]=$i;
         }
       $Year = array();
       for ($i=$this->GetOption('start_year',($today['year']-10));$i<$this->GetOption('end_year',($today['year']+10))+1;$i++)
         {
         	$Year[$i]=$i;
         }
		if ($this->HasValue())
			{
			$today['mday'] = $this->GetArrayValue(0);
			$today['mon'] = $this->GetArrayValue(1);
			$today['year'] = $this->GetArrayValue(2);			
			}
		else if ($this->GetOption('default_year','-1') != '-1')
		   {
         $today['year'] = $this->GetOption('default_year','-1');
         }

      $ret = array();
      $day = new stdClass();
	  $js = $this->GetOption('javascript','');

      $day->input = $mod->CreateInputDropdown($id, 'fbrp__'.$this->Id.'[]', $Days, -1, $today['mday'], 'id="'.$id. '_'.$this->Id.'_1" '.$js);
 		$day->title = $mod->Lang('day');
 		$day->name = '<label for="'.$id.'_'.$this->Id.'_1">'.$mod->Lang('day').'</label>';
 		array_push($ret, $day);

      $mon = new stdClass();
      $mon->input = $mod->CreateInputDropdown($id, 'fbrp__'.$this->Id.'[]', $this->Months, -1, $today['mon'], 'id="'.$id. '_'.$this->Id.'_2" '.$js);
 		$mon->title = $mod->Lang('mon');
 		$mon->name = '<label for="'.$id.'_'.$this->Id.'_2">'.$mod->Lang('mon').'</label>';
 		array_push($ret, $mon);

      $yr = new stdClass();
      $yr->input = $mod->CreateInputDropdown($id, 'fbrp__'.$this->Id.'[]', $Year, -1, $today['year'],'id="'.$id. '_'.$this->Id.'_3" '.$js);
      $yr->name = '<label for="'.$id.'_'.$this->Id.'_3">'.$mod->Lang('year').'</label>';
      $yr->title = $mod->Lang('year');
      array_push($ret,$yr);
      return $ret;
	}

   function CompareTo($val)
   {
      $td = 0;
      $od = 0;
      if ($this->HasValue())
			{
			$td = mktime ( 1, 1, 1, $this->GetArrayValue(1),  $this->GetArrayValue(0), $this->GetArrayValue(2) );
			}
		$o = $val->GetValue();
      if ($o->HasValue())
			{
			$od = mktime ( 1, 1, 1, $o->GetArrayValue(1),  $o->GetArrayValue(0), $o->GetArrayValue(2) );
			}
      if ($td == $od)
         {
         return 0;
         }
      return ($td < $od) ? -1 : 1;
   }



	function GetHumanReadableValue($as_string=true)
	{
		$mod = &$this->form_ptr->module_ptr;
		if ($this->HasValue())
			{
			$theDate = mktime ( 1, 1, 1, $this->GetArrayValue(1),  $this->GetArrayValue(0), $this->GetArrayValue(2) );
			$ret = date($this->GetOption('date_format','j F Y'), $theDate);
			}
		else
			{
			$ret = $mod->Lang('unspecified');
			}
		if ($as_string)
			{
			return $ret;
			}
		else
			{
			return array($ret);
			}
	}

	function PrePopulateAdminForm($formDescriptor)
	{
		$mod = &$this->form_ptr->module_ptr;
      $today = getdate();
		$main = array(
			array($mod->Lang('title_date_format'),
            		array($mod->CreateInputText($formDescriptor, 'fbrp_opt_date_format',
            		$this->GetOption('date_format','j F Y'),25,25),$mod->Lang('help_date_format'))
		    ),
		   array($mod->Lang('title_start_year'),
            		$mod->CreateInputText($formDescriptor, 'fbrp_opt_start_year',
            		    $this->GetOption('start_year',($today['year']-10)),10,10)),
		   array($mod->Lang('title_end_year'),
            		$mod->CreateInputText($formDescriptor, 'fbrp_opt_end_year',
            		    $this->GetOption('end_year',($today['year']+10)),10,10)),
		   array($mod->Lang('title_default_year'),
            		array($mod->CreateInputText($formDescriptor, 'fbrp_opt_default_year',
            		    $this->GetOption('default_year','-1'),10,10),$mod->Lang('title_default_year_help'))
         )
      );
		return array('main'=>$main,array());
	}

}

?>

JeremyBASS

Re: FormBuilder DatePickerField remove day dropdown, only have month and year

Post by JeremyBASS »

this may get you going...

element scrubber| Good for dropdowns of form templates in NEWs etc...

Hope that helps

cheers
jeremyBass
mvandiermen
Forum Members
Forum Members
Posts: 83
Joined: Mon Nov 03, 2008 1:28 pm

Re: FormBuilder DatePickerField remove day dropdown, only have month and year

Post by mvandiermen »

Thanks. I did the job with a different system now.
JeremyBASS

Re: FormBuilder DatePickerField remove day dropdown, only have month and year

Post by JeremyBASS »

Oh... sorry I didn't get to you quicker...

Cheers
Jeremy
mvandiermen
Forum Members
Forum Members
Posts: 83
Joined: Mon Nov 03, 2008 1:28 pm

Re: FormBuilder DatePickerField remove day dropdown, only have month and year

Post by mvandiermen »

I would have waited but I saw the checkout system of zencart a bonus so I use their attributes function to build my form. Thank you for your time, I really appreciate the help I get in forums and like to repay the offer by helping others.
jk
Forum Members
Forum Members
Posts: 30
Joined: Thu Dec 04, 2008 4:47 pm

Re: FormBuilder DatePickerField remove day dropdown, only have month and year

Post by jk »

I am trying to do something similar - some of my fields do want the day option and others do not.  I am not sure how to best to try and approach this.  Should I try to create a new field type and if so how?
mvandiermen
Forum Members
Forum Members
Posts: 83
Joined: Mon Nov 03, 2008 1:28 pm

Re: FormBuilder DatePickerField remove day dropdown, only have month and year

Post by mvandiermen »

you can create a blank drop down
Fields;
- Select month:
- January
- February
- Etc

It wont automatically be on the current month but at least the user can pick a month only
Post Reply

Return to “Modules/Add-Ons”