'type', 'ip_hostname' => 'hostname', 'ip_mac' => 'mac', 'ip_description' => 'description'] as $field => $key) { $post[$key] = array_key_exists($field, $_POST) ? (is_scalar($_POST[$field]) ? (string) $_POST[$field] : '') : (string) ($row[$field] ?? ''); } // A reservation documented without its MAC (an import) can still be changed, until a MAC is sent $post['allow_no_mac'] = $row && $row['ip_type'] === 'Reservation' && (string) $row['ip_mac'] === '' && !array_key_exists('ip_mac', $_POST); return $post; }; $ip_refuse = function ($message) use (&$return_arr) { http_response_code(400); $return_arr['success'] = "False"; $message = rtrim(html_entity_decode(strip_tags($message), ENT_QUOTES | ENT_HTML5, 'UTF-8')); $return_arr['message'] = preg_match('/[.!?]$/', $message) ? $message : "$message."; echo json_encode($return_arr); exit(); }; if (array_key_exists('ip_type', $_POST) && !isset(NETWORK_IP_TYPES[$_POST['ip_type']])) { $ip_refuse('ip_type is one of: ' . implode(', ', array_keys(NETWORK_IP_TYPES)) . '.'); }