如何用PHP调取HTML中的复选框的值,如何从html表单获取未经检查的复选框到php并为其赋值?(how can I get an unchecked checkbox from a html fo...

如何从html表单获取未经检查的复选框到php并为其赋值?(how can I get an unchecked checkbox from a html form to php and give a value to it?)

我正在博客中工作,我正在尝试处理注册表单的新闻通讯复选框...当用户标记复选框时我没有问题得到'是'作为结果我把它带到数据库,但当用户离开复选框未选中时,我得到一个未定义的索引,只是无法继续使用寄存器,这是我到目前为止的代码

html表单

//declared variable for the users input

$newsletter=$_POST['newsletter'];

//the condition for the checkbox

if(isset( $newsletter)){

$newsletter=="yes";

}else{

$newsletter=="no";

}

//then I insert the variable $newsletter through a prepared query...

I'm working in a blog and I'm trying to deal with the newsletter checkbox of the register form... when the user marks the checkbox I have no problem to get 'yes' as result and I take that to the data base, but when the user leaves the checkbox unchecked I got an undefined index and just can't continue with the register, here's the code I have so far

the html form

the

//declared variable for the users input

$newsletter=$_POST['newsletter'];

//the condition for the checkbox

if(isset( $newsletter)){

$newsletter=="yes";

}else{

$newsletter=="no";

}

//then I insert the variable $newsletter through a prepared query...

原文:https://stackoverflow.com/questions/36680658

更新时间:2020-02-13 06:03

最满意答案

使用空检查。

if(!empty($_POST['newsletter'])){

}

Use empty check.

if(!empty($_POST['newsletter'])){

}

相关问答

我们可以使用JavaScript来做到这一点,不需要jQuery。 只需传递更改后的元素并让JavaScript处理它。 HTML

syn

JS function doalert(checkboxElem) {

if (checkboxElem.checked) {

...

如果取消选中,复选框不会返回任何值? 所以,如果你想要检查它是否被检查,你最好使用PHP的isset方法。 例如: $isFree = isset($_POST['free'] 然后使用这个$isFree变量插入到DB中。 Checkbox doesn't return any value if it is unchecked? So, if you want such to check whether it was checked or not you better use the isset

...

这里是代码看看它是否工作 - <?php

session_start();//session start should be in the beginning of the code

if(isset($_POST) && !empty($_POST)){

$la = isset($_POST['la']) ? 1 : 0; // if the box is checked, return 1. if not, return 0

if($la == 1 ||

...

使用它来获得正确的值。 $("#terms_and_conditions").is(':checked')

Use this instead to get the right value. $("#terms_and_conditions").is(':checked')

嗨试试这个代码, $('#Submit1').click(function () {

var grid = $("#grid12").data("kendoGrid");

var selected = grid.tbody.find('td').find('.chkbxq').is(':checked');

var checkid = grid.tbody.find('td').find('.chkbxq').attr('

...

好的,我所知道的是你要反转复选框。 如果已经检查过,请不要使用表单发送值。 如果未选中,则使用表单发送值。 如果您想在复选框点击时提交表单,我只是没有得到。 使用具有该值的相同名称进行隐藏输入。 当复选框被选中时,禁用隐藏盒。

$('#my_

...

两件小事: function checkAll() {

var checks = document.getElementsByName("checkGroup[]");

for (var i=0; i < checks.length; i++) {

checks[i].checked = true;

}

}

getElementByName应该是getElementsByName ,而checkGroup应该是checkGroup[] 。 除此之外你的代码

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值