Created
June 2, 2016 17:21
-
-
Save bwente/475044a776cc48e6705c5db090a5969e to your computer and use it in GitHub Desktop.
Dynamic form selector for years
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//[[!FormItYearOptions? &name=`rentexpireYear` &futureYears=`3` &pastYears=`1` &selectedOffset=`1`]] | |
$name = $modx->getOption('name',$scriptProperties,'year'); | |
$futureYears = $modx->getOption('futureYears',$scriptProperties,'5'); | |
$pastYears = $modx->getOption('pastYears',$scriptProperties,'1'); | |
$selectedOffset = $modx->getOption('selectedOffset',$scriptProperties,'1'); | |
$reverse = $modx->getOption('reverse',$scriptProperties,''); | |
$thisYear = date('Y'); | |
$startYear = ($thisYear - $pastYears); | |
$endYear = ($thisYear + $futureYears); | |
$selectYear = ($thisYear + $selectedOffset); | |
$range = range($startYear, $endYear); | |
if($reverse){ | |
$range = array_reverse($range); | |
} | |
foreach ($range as $year) { | |
$selected = ""; | |
if($year == $selectYear) { $selected = " selected"; } | |
$output .= '<option value="'. $year .'" '. $selected . ' [[!+fi.'.$name.':FormItIsSelected=`$year`]]>' . $year . '</option>'; | |
} | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment