【发布时间】:2019-07-12 02:35:19
【问题描述】:
我正在尝试使用多个提交按钮从多个复选框发布数据。 重要的是:提交按钮不是表单的一部分,因为它们位于网站的不同位置。
这是我目前所拥有的:
<form class="checkboxform" action="" method="post">
<input type="checkbox" name="check_list[]" value="C/C++"><label>C/C++</label><br/>
<input type="checkbox" name="check_list[]" value="Java"><label>Java</label><br/>
<input type="checkbox" name="check_list[]" value="PHP"><label>PHP</label><br/>
</form>
提交按钮:
<button type="button" id="delete" name="delete" onclick="submitForm()" value="Delete"/>Delete</button>
<button type="button" id="move" name="move" onclick="submitForm()" value="Move"/>Move</button>
<button type="button" id="copy" name="copy" onclick="submitForm()" value="Copy"/>Copy</button>
ajax:
function submitForm(url){
var data = $(".checkboxform").serialize();
$.ajax({
type : 'POST',
url : url,
data: data,
success : function(data){
$(".echo").html(data);
}
});
};
php:
if($_POST['delete']) {
if(isset($_POST['check_list'])){//to run PHP script on submit
if(!empty($_POST['check_list'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_list'] as $selected){
echo $selected."</br>";
}
// code for delete goes here
echo 'Files are deleted!';
}
}
}
if($_POST['move']) {
if(isset($_POST['check_list'])){//to run PHP script on submit
if(!empty($_POST['check_list'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_list'] as $selected){
echo $selected."</br>";
}
//code for moving files goes here
echo 'Files are moved!';
}
}
}
if($_POST['copy']) {
if(isset($_POST['check_list'])){//to run PHP script on submit
if(!empty($_POST['check_list'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_list'] as $selected){
echo $selected."</br>";
}
// code for copy goes here
echo 'Files are copied!';
}
}
}
通过提交,php 不处理数据。我做错了什么?有人可以帮我吗?
所有代码都在同一个文件中,名为index.php
【问题讨论】:
-
您的按钮不是
-
好的。当按钮在表单之外时,我怎样才能实现这一点?因为按钮在网站上的不同位置
标签: php jquery ajax button checkbox