arcadeicons
Member
I have an element designed to accept scores, and I run php validations against the scores. If there is a comma in the score entered it breaks the validation script. I have the field format set to integer and number format to yes.
Some users will use commas when entering their scores so I have to be able to accommodate that.
my validation code.
Some users will use commas when entering their scores so I have to be able to accommodate that.
my validation code.
PHP:
// get score
$gameScore = $formModel->formData[submit_score___gamescore];
// get joins, they'll probably be arrays, so have to check for that
$tournID = $formModel->formData[submit_score___tournID_raw];
$tournID = is_array($tournID) ? $tournID[0] : $tournID;
$eventID = $formModel->formData[submit_score___eventID_raw];
$eventID = is_array($eventID) ? $eventID[0] : $eventID;
$gameID = $formModel->formData[submit_score___gameID_raw];
$gameID = is_array($gameID) ? $gameID[0] : $gameID;
$locID = $formModel->formData[submit_score___collectiontype_raw];
$locID = is_array($locID) ? $locID[0] : $locID;
$playerID = $formModel->formData[submit_score___userID_raw];
$playerID = is_array($playerID) ? $playerID[0] : $playerID;
// build a query to find any existing rows with higher score
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
->select('*')
->from('submit_score')
->where('tournID = ' . $myDb->quote($tournID))
->where('eventID = ' . $myDb->quote($eventID))
->where('gameID = ' . $myDb->quote($gameID))
->where('collectiontype = ' . $myDb->quote($locID))
->where('userID = ' . $myDb->quote($playerID))
->where('gamescore >= ' . $gameScore);
$myDb->setQuery($myQuery);
$scores = $myDb->loadObjectList();
// returns false if we found any rows
return empty($scores);