function mp3player_player_form_validate in MP3 Player 6.2
Same name and namespace in other branches
- 7.2 mp3player.module \mp3player_player_form_validate()
form_validate.
File
- ./
mp3player.module, line 469 - mp3player main module file.
Code
function mp3player_player_form_validate($form, &$form_state) {
$players = mp3player_players();
foreach ($players as $player) {
if ($player['name'] == $form_state['values']['name']) {
form_set_error('name', t('Player name has to be unique.'));
}
}
if (preg_match('/[^0-9a-zA-Z_]/', $form_state['values']['name'])) {
form_set_error('name', t('Please only use alphanumeric characters, and underscores (_) for player names.'));
}
if ($form_state['values']['name'] != '' && strlen($form_state['values']['name']) >= 20) {
form_set_error('name', t('Player name must be 20 characters long or shorter.'));
}
if (!is_numeric($form_state['values']['initialvolume'])) {
form_set_error('initialvolume', t('Initial Volume must be an integer'));
}
if ($form_state['values']['initialvolume'] < 0 || $form_state['values']['initialvolume'] > 100) {
form_set_error('initialvolume', t('Volume must be between 0 and 100.'));
}
if (!is_numeric($form_state['values']['buffer'])) {
form_set_error('buffer', t('Buffer must be an integer.'));
}
$percentage = strstr($form_state['values']['width'], '%');
if (!is_numeric($form_state['values']['width']) && $percentage != '%') {
form_set_error('width', t('Width must be an integer or percentage.'));
}
// fields to test hex value of.
$hextest = array(
'bg',
'leftbg',
'lefticon',
'voltrack',
'volslider',
'rightbg',
'rightbghover',
'righticon',
'righticonhover',
'loader',
'track',
'tracker',
'border',
'skip',
'text',
);
$bgcolor = $form_state['values']['pagebg'];
$transbg = $form_state['values']['transparentpagebg'];
if ($transbg == 'yes') {
if ($bgcolor == '') {
form_set_error('pagebg', 'Please set a background color');
}
else {
$hextest[] = 'pagebg';
}
}
foreach ($hextest as $test) {
if (isset($form_state['values'][$test]) && ($res = mp3player_validate_hex($form_state['values'][$test]))) {
form_set_error($test, $res);
}
}
}