在表单中显示选中的复选框以形成POST提交 [英] Display a checked checkbox in a form to form POST submission

查看:316
本文介绍了在表单中显示选中的复选框以形成POST提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此向导需要显示上一个发布的值

I have this wizard that needs to display the previous posted value

index.html

<form method="post" action="posted.php">
<input type="text" name="surname" value="" placeholder="Surname" />
<input type="text" name="firstname" value="" placeholder="Firstname" />
<input type="checkbox" name="php" />
<input type="checkbox" name="jquery" />
<input type="checkbox" name="python" />
<input type="submit" value="Submit" />
</form>

类似的形式只有这一次我知道从 $ _ POST

in the posted.php i have a similar form only this time i know the value from $_POST

   <form method="post" action="finish.php">
    <input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
    <input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
    <input type="checkbox" name="php" />
    <input type="checkbox" name="jquery" />
    <input type="checkbox" name="python" />
    <input type="submit" value="Submit" />
    </form>

我很难想出一个解决方案,已经看到过几个解决方案,例如 http://stackoverflow.com/a/11424091/1411148 ,但我想知道是否有更多的解决方案在html5或jquery中。

I am having a hard time trying to come up with a solution that shows what checkbox was checked.I have seen several solutions like http://stackoverflow.com/a/11424091/1411148 but i wondering if there more solution probably in html5 or jquery.

我如何显示复选框被选中的?我的问题是,< input type = > > >

How can i show what checkbox was checked?.The probem i am having is that <input type="checkbox" name="jquery" checked /> checked checks the checkbox and no post data can be added to show what the user checked.

推荐答案

这将是一种方法:

<form method="post" action="finish.php">
    <input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
    <input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
    <input type="checkbox" name="php" <?php if (isset($_POST['php'])) echo 'checked="checked"'; ?> />
    <input type="checkbox" name="jquery" <?php if (isset($_POST['jquery'])) echo 'checked="checked"'; ?> />
    <input type="checkbox" name="python" <?php if (isset($_POST['python'])) echo 'checked="checked"'; ?> />
    <input type="submit" value="Submit" />
</form>

这篇关于在表单中显示选中的复选框以形成POST提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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