Implement validation check for grid locator input
这个提交包含在:
父节点
f17f148d01
当前提交
c5ff0df369
共有 2 个文件被更改,包括 25 次插入 和 1 次删除
|
|
@ -44,6 +44,7 @@ class QSO extends CI_Controller {
|
|||
$this->form_validation->set_rules('start_date', 'Date', 'required');
|
||||
$this->form_validation->set_rules('start_time', 'Time', 'required');
|
||||
$this->form_validation->set_rules('callsign', 'Callsign', 'required');
|
||||
$this->form_validation->set_rules('locator', 'Locator', 'callback_check_locator');
|
||||
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
|
|
@ -443,4 +444,26 @@ class QSO extends CI_Controller {
|
|||
header('Content-Type: application/json');
|
||||
echo $input;
|
||||
}
|
||||
|
||||
function check_locator($grid) {
|
||||
$grid = $this->input->post('locator');
|
||||
// Allow empty locator
|
||||
if (preg_match('/^$/', $grid)) return true;
|
||||
// Allow 6-digit locator
|
||||
if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Ra-r]{2}$/', $grid)) return true;
|
||||
// Allow 4-digit locator
|
||||
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true;
|
||||
// Allow 4-digit grid line
|
||||
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true;
|
||||
// Allow 4-digit grid corner
|
||||
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true;
|
||||
// Allow 2-digit locator
|
||||
else if (preg_match('/^[A-Ra-r]{2}$/', $grid)) return true;
|
||||
// Allow 8-digit locator
|
||||
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true;
|
||||
else {
|
||||
$this->form_validation->set_message('check_locator', 'Please check value for grid locator ('.strtoupper($grid).').');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,8 @@
|
|||
<label for="locator" class="col-sm-3 col-form-label"><?php echo $this->lang->line('gen_hamradio_locator'); ?></label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" class="form-control form-control-sm" name="locator" id="locator" value="">
|
||||
<small id="locator_info" class="form-text text-muted">Enter multiple (4-digit) grids separated with commas. For example: IO77,IO78</small>
|
||||
<small id="locator_info" class="form-text text-muted"></small>
|
||||
<small id="locator_format" class="form-text text-muted">Enter multiple (4-digit) grids separated with commas. For example: IO77,IO78</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
正在加载…
在新工单中引用