如何将值从 DIV 元素提交到基于 PHP 的表单中 [英] How to submit value from DIV element into a PHP-based form

查看:21
本文介绍了如何将值从 DIV 元素提交到基于 PHP 的表单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于复选框的 DIV 元素.我想将其值"属性提交到基于 PHP 的表单中,但它不会将 DIV 响应传递给 PHP 文件.

I have a DIV element that works like a checkbox. I want to submit its 'value' attribute into a PHP-based form, but it won't pass the DIV response to the PHP file.

HTML:

 <form action="test.php" method="post">
    <div id="test1" value="testvalue" name="test" checked="checked"></div>
    <input type="submit" />
 </form>

PHP:

<?php
$test = $_POST['test'];
echo $test;
?>

推荐答案

只有表单元素被回发到服务器.如果要发送值,则需要创建一个输入元素.您可以考虑制作一个 <input type="hidden" name="test" value="testvalue".

Only form elements are posted back to the server. You need to create an input element if you want the value sent. You could consider making an <input type="hidden" name="test" value="testvalue".

响应您使用 jQuery 注释制作的自定义复选框,您可以使用 jQuery 设置隐藏输入元素的值.这将让您继续使用 div,但有一个值被发送回服务器.

In response to your custom checkbox made with jQuery comment, you could use jQuery to set the value of the hidden input element. This will let you continue to use the div but have a value that gets sent back to the server.

这篇关于如何将值从 DIV 元素提交到基于 PHP 的表单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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