php - 从表单中检查外部数组

I've created a form in html. in this form you can specify the operating system. The form looks like this:

<input type="hidden" name="toshibaproduct" value="001"/>
<input type="hidden" name="toshibamerk" value="toshiba"/>
<input type="hidden" name="toshibamodel" value="Sattelite A100-510"/>
Operating system <select name="beschikbaarheid" value="true">
    <option value="xp">Windows XP</option>
    <option value="vista">Windows Vista</option>
    <option value="linux">Linux</option>
</select>
Aantal: <input type="text" size=2 maxlength=3 name="toshibaaantal" value="0"/>
<input type="hidden" name="toshibaprijs" value="999.99"/>
<input type="image" src="bestel.jpg" border=0 value="bestellen"/>

I've also created an external function which i have included in the page which looks like this:

<?php
function beschikbaarheid($merk, $os)
{
    $beschikbaar = array(
        "Toshiba" => array("xp" => true, "vista" => false, "linux" => true),
        "Acer" => array("xp" => true, "vista" => true, "linux" => true),
        "Hp" => array("xp" => true, "vista" => false, "linux" => true));
    return ($beschikbaar[$merk][$os]);
}
?>

My plan is to let the form check in the external function if an operating system is available or not, and if not return a message that it's sold out. if it's available it should just continue with the rest of the script (which works btw, but it not included here).

Thing is, i don't know how to make the form check the array in the external function. I am also wondering if it's a problem that only the operatings system is checked in an external function and not the rest of the form like the quantity for instance.

Updated HTML

<head>
    <!-- include jQuery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>

<input type="hidden" name="toshibaproduct" value="001" />
<input type="hidden" name="toshibamerk" value="toshiba" />
<input type="hidden" name="toshibamodel" value="Sattelite A100-510" />
Maker
<select name="maker" value="true" id="maker">
    <option value="toshiba">Toshiba</option>
    <option value="acer">Acer</option>
    <option value="hp">Hp</option>
</select>
Operating system 
<select name="beschikbaarheid" value="true" id="operationSystem">
    <option value="xp">Windows XP</option>
    <option value="vista">Windows Vista</option>
    <option value="linux">Linux</option>
</select>
Aantal: <input type="text" size=2 maxlength=3 name="toshibaaantal" id="quantity" value="0" />
<input type="hidden" name="toshibaprijs" value="999.99" />
<input type="button" value="bestellen" id="submitData" />

<span id="messages"></span>

Ajax

<!-- Ajax -->
<script type="text/javascript">
$('#submitData').click(function(){
    var selectedOs = $('#operationSystem').find('option:selected').val();
    var selectedMaker = $('#maker').find('option:selected').val();
    var selectedQuantity = $('#quantity').val();
    if(selectedQuantity == 0 || selectedQuantity == ''){
        $('#messages').text('Please provide valid information');
        return false;
    }
   // You can perform an ajax request using the .ajax() method
    $.ajax({
        type: 'POST',
        url: 'beschikbaarheid.php', // This is the url that will be requested
        data: {operation_system: selectedOs, maker: selectedMaker, quantity: selectedQuantity},
        success: function(data){ 
            if(data){
                $('#messages').text('Available');
            }else{
                $('#messages').text('Not available');
            }
        },
    });

});
</script>

Server-side script (beschikbaarheid.php)

<?php
if(isset( $_POST['quantity'] )) {
    $operatingSystem  = $_POST['operation_system'];
    $maker  = $_POST['maker'];
    $quantity  = $_POST['quantity'];
    echo beschikbaarheid($operatingSystem, $maker, $quantity);
}
function beschikbaarheid($operatingSystem, $maker, $quantity)
{
    // I did't used the quantity section
    // Please use it if needed
    // Also this structure is not much prefered, I just used this becasuse you might have some out put like this.
    $beschikbaar = array(
        "toshiba" => array ("xp" =>false, "vista" => false, "linux" => true), 
        "hp" => array ("xp" =>true, "vista" => false, "linux" => true),
        "acer" => array ("xp" =>true, "vista" => false, "linux" => true)
    ); 
    return $beschikbaar[$maker][$operatingSystem];
}
?>

There are different ways to achieve this, I hope this helps.

Try writing JavaScript or jQuery functions if you need to check it before submitting the form. Else, you can call the function in the page where the data is submitting. You can then validate the field and generate the response.

If, for instance you had a JSON file with the list of available operating systems you could use that to check the choice against the list.

`os.json`
[
    "Windows Vista", "Windows XP", "OSX", "Linux"
]
some other PHP file
<?php
function is_os_available($os) {
    return in_array($os, json_decode(file_get_contents('os.json')));
}

Hope this helps,
Sean