我想验证我的复选框是否在php中检查过,如果是,我想回复" Hello word"。 这是我的HTML代码:
/***
Copyright (c) 2016 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
From _The Busy Coder's Guide to Android Development_
https://commonsware.com/Android
*/
package com.commonsware.android.parcelable.marshall;
import android.os.Parcel;
import android.os.Parcelable;
// inspired by https://stackoverflow.com/a/18000094/115145
public class Parcelables {
public static byte[] toByteArray(Parcelable parcelable) {
Parcel parcel=Parcel.obtain();
parcelable.writeToParcel(parcel, 0);
byte[] result=parcel.marshall();
parcel.recycle();
return(result);
}
public static <T> T toParcelable(byte[] bytes,
Parcelable.Creator<T> creator) {
Parcel parcel=Parcel.obtain();
parcel.unmarshall(bytes, 0, bytes.length);
parcel.setDataPosition(0);
T result=creator.createFromParcel(parcel);
parcel.recycle();
return(result);
}
}
php:
<form class="checkclass">
<input type="checkbox" name="checkbox1"> 4K </input>
</form>
但它不起作用,我真的不知道如何解决这个问题。 有人可以帮助我吗?
答案 0 :(得分:0)
isset($_GET['checkbox1']))
不起作用,因为它正在检查URL查询字符串。不是表格提交。使用$ _POST而不是$ _GET。所以它会是这样的:
if (isset($_POST['checkbox1'])) {
// Go ahead and do stuff because it is checked
}
答案 1 :(得分:-1)
您正在发送GET请求,但作为POST请求处理。以下任一代码都可以使用:
<form class="checkclass" method="POST">
<input type="checkbox" name="checkbox1"> 4K </input>
</form>
<?php
if (isset($_POST['checkbox1'])) {
echo "Hello world!";
}
?>
<form class="checkclass">
<input type="checkbox" name="checkbox1"> 4K </input>
</form>
<?php
if (isset($_GET['checkbox1'])) {
echo "Hello world!";
}
?>