如何从<select> html标签PHP </select>中选择一段代码

时间:2013-11-14 19:31:35

标签: php html

我有一个选择下拉列表:

    <form action="member.php" method="POST" enctype="multipart/form-data">
<table width="80%">
    <tr>
        <td class="borderblack">Select Phone Type:
            <select name="phone_type">
                    <option value="escene" name="escene">Escene</option>
                    <option value="grandstream" name="grandstream">Grandstream</option>
            </select>

            <input type="submit" name="phone_typesub">
        </td>


        <td class="borderblack">
            <label for="file">Upload XML:</label>
            <input type="file" name="file" id="file">
            <input type="submit" name="submit" >
        </td>   
</form>

根据所选的下拉选项,我想运行包含在不同文件中的特定代码块。我想知道是否有人可以建议我。 (php文件中有2个代码块)

4 个答案:

答案 0 :(得分:0)

member.php中的类似内容:

if($_POST['phone_type']=='escene'){
    import 'escene_handler.php';       // run this if they selected 'escene'
}else if($_POST['phone_type']=='grandstream'){
    import 'grandstream_handler.php';  // run this if they selected 'grandstream'
}

在提交表单时会调用它。

答案 1 :(得分:0)

我认为AJax是解决这个问题的最佳解决方案。

答案 2 :(得分:0)

您可以使用简单的switch声明:

if (!empty($_POST)) {
    switch ($_POST['phone_type']) {
        case 'escene':
            // run your code when 'escene' is selected
            break;
        case 'grandstream':
            // run your code when 'grandstream' is selected
            break;
        default:
            // run default code, when non of the above is selected, or ignore
    }
}

答案 3 :(得分:0)

<?php if(isset($_POST['YourDropDownName']) && $_POST['YourDropDownName'] == "Option1Value")
{
    //do stuff here...
}
else if(isset($_POST['YourDropDownName']) && $_POST['YourDropDownName'] == "Option2Value")
{
    //do other stuff here...
}?>`

这可行。