我得到了以下一段代码(为此问题目的缩写)
$(function() {
var professions = [{"name":"Altenpflegehelfer","value":"3"},{"name":"Altenpfleger","value":"4"},{"name":"Änderungsschneider","value":"2"},{"name":"Anlagenmechaniker","value":"5"},{"name":"Anlagenmechaniker für Sanitär-, Heizungs- und Klimatechnik (früher: Zentralheizungs- und Lüftungsbauer)","value":"6"},{"name":"Asphaltbauer","value":"7"}];
$('#profession').dropdown({
values: professions,
fullTextSearch: true,
});
});

<head>
<!-- jQuery -->
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<!-- Semantic UI -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.14/semantic.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.14/semantic.min.css" />
</head>
<body>
<form class="ui large form" action="post.php" method="post">
<div class="one field">
<label for="profession">Profession</label>
<select name="profession" class="ui search dropdown" id="profession"></select>
</div>
<button type="submit" class="ui fluid large teal submit button">Submit</button>
</form>
<script>
</script>
</body>
&#13;
问题是,当我发送表单时,PHP中的$ _REQUEST变量为空。
您只需使用以下内容创建新文件post.php即可对其进行测试:
<?php echo var_dump($_REQUEST); ?>
我做错了吗?
答案 0 :(得分:0)
$(function() {
var professions = [{"name":"Altenpflegehelfer","value":"3"},{"name":"Altenpfleger","value":"4"},{"name":"Änderungsschneider","value":"2"},{"name":"Anlagenmechaniker","value":"5"},{"name":"Anlagenmechaniker für Sanitär-, Heizungs- und Klimatechnik (früher: Zentralheizungs- und Lüftungsbauer)","value":"6"},{"name":"Asphaltbauer","value":"7"}];
$('.ui.dropdown').dropdown({
placeholder: "Search your profession",
values: professions,
fullTextSearch: true,
});
});
<head>
<!-- jQuery -->
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<!-- Semantic UI -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.14/semantic.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.14/semantic.min.css" />
</head>
<body>
<form class="ui large form" action="post.php" method="post">
<div class="field"> <!-- creating a field -->
<label>Profession</label>
<div class="ui search labeled selection dropdown">
<input name="profession" type="hidden"> <!-- store the selected value that gonna be posted -->
<span class="text"></span>
<i class="dropdown icon"></i>
</div>
</div>
<button type="submit" class="ui fluid large teal submit button">Submit</button>
</form>
</body>