Last active
March 28, 2018 19:05
-
-
Save bwente/8b973ba2671d8e6f717b545be79a5728 to your computer and use it in GitHub Desktop.
FormItNumberRanges
This file contains hidden or 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 | |
// [[!FormItNumberRanges? &numberStart=`50000` &numberStop=`200000` &numberStep=`10000` &numberSeparator=` – ` &fieldName=`loanAmount` &fieldValue=`low` ]] | |
$numberStart = $modx->getOption('numberStart',$scriptProperties,'50000'); | |
$numberStop = $modx->getOption('numberStop',$scriptProperties,'200000'); | |
$numberStep = $modx->getOption('numberStep',$scriptProperties,'10000'); | |
$numberSeparator = $modx->getOption('numberSeparator',$scriptProperties,' – '); | |
$numberFormat = $modx->getOption('numberFormat',$scriptProperties,'USD'); | |
$fieldName = $modx->getOption('fieldName',$scriptProperties,''); | |
$fieldValue = $modx->getOption('fieldValue',$scriptProperties,'low'); | |
$reverse = $modx->getOption('reverse',$scriptProperties,''); | |
$selectNumber = $modx->getOption('selectNumber',$scriptProperties,''); | |
$range = range($numberStart, $numberStop, $numberStep); | |
$iterations = ($numberStop-$numberStart)/$numberStep; | |
if($reverse){ | |
$range = array_reverse($range); | |
} | |
foreach ($range as $iteration) { | |
$selected = ""; | |
$i++; | |
if($selectNumber == $iteration) { $selected = " selected"; } | |
if($i > 1) { $rangePlus = 1; } | |
if($fieldValue == "low") { $rangeValue = $iteration; } else {$rangeValue = ($iteration+$numberStep);} | |
if($numberSeparator){ | |
$output .= '<option value="'. $rangeValue .'" '. $selected . ' [[!+fi.'.$fieldName.':FormItIsSelected=`'.$rangeValue.'`]]>' . number_format($iteration+$rangePlus) . $numberSeparator . number_format($iteration+$numberStep) . '</option>'; | |
} else { | |
$output .= '<option value="'. $iteration .'" '. $selected . ' [[!+fi.'.$fieldName.':FormItIsSelected=`'.$iteration.'`]]>' . number_format($iteration) . '</option>'; | |
} | |
} | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment