提交表单后,PHP会保留复选框 [英] PHP keep checkbox checked after submitting form

查看:77
本文介绍了提交表单后,PHP会保留复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个联系表和captcha在那里。我想保持提交表单后检查检查。我发布了文本框的值,它显示正确,但复选框不起作用。这里是我的代码。

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title>无标题文档< / title>
< / head>

< body>
< form action =name =frmSubmitmethod =post>
< input type =checkboxname =txtCheckvalue =<?php echo $ _POST ['txtCheck'];?> />< br />
< label>名称< / label>< br />
< input type =textname =txtNameid =NameTextBoxvalue =<?php echo $ _POST ['txtName'];?> />
< br />
< label> E Mail< / label>< br />
< input type =textname =txtEmailid =EmailTextBoxvalue =<?php echo $ _POST ['txtEmail'];?> />
< input name =BtnSubmittype =submitonclick =MM_validateForm('NameTextBox','','R','EmailTextBox','','R'); return document.MM_returnValue value =发送/>
< / form>
< / body>
< / html>

如何在提交表单后保留复选框?

解决方案

更改

 < input type =checkboxname = txtCheckvalue =<?php echo $ _POST ['txtCheck'];?> />< br /> 

 < input type =checkboxname =txtCheckvalue =your value<?php if(isset($ _ POST ['txtCheck']))echochecked ='checked'; ?> />< br /> 

这将保持复选框被选中。


Hi all i have a contact form and captcha is there. i want keep the check is checked after submitting the form. I posted the textbox values and it showing correctly but checkbox is not working. here is my code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action = "" name="frmSubmit" method="post">
<input type="checkbox" name="txtCheck" value="<?php echo $_POST['txtCheck'];?>"  /><br />
<label>Name</label><br />
<input type="text" name="txtName" id="NameTextBox" value="<?php echo $_POST['txtName']; ?>" />
<br />
<label>E Mail</label><br />
 <input type="text" name="txtEmail" id="EmailTextBox" value="<?php  echo $_POST['txtEmail'];?>" />
 <input name="BtnSubmit" type="submit" onclick="MM_validateForm('NameTextBox','','R','EmailTextBox','','R');return document.MM_returnValue" value="Send" />
</form>
</body>
</html>

How to keep check box after submitting the form.?

解决方案

change

<input type="checkbox" name="txtCheck" value="<?php echo $_POST['txtCheck'];?>"  /><br />

to

<input type="checkbox" name="txtCheck" value="your value" <?php if(isset($_POST['txtCheck'])) echo "checked='checked'"; ?>  /><br />

this will keep checkbox checked..

这篇关于提交表单后,PHP会保留复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆