在PHP中获取自定义属性值

塞巴斯蒂安

我尝试使用我使用PHP创建的自定义属性获取输入字段的值。这是我的代码:

<form action="uploadform.php" method="post"> 
<input type="text" name="email" id="email" mynewattribute="myemail">
<input type="submit" name="submit">
</form>

//uploadform.php
<?php
//I know $name = $_POST['email']; will give me the value but I would like to get the value of the input field with "mynewattribute" and not name. Is it possible?
?>
即时通讯

Web浏览器不知道如何处理您的自定义属性,因此将其忽略。提交表单时发送的唯一数据是“成功”元素的值。因此,您的自定义数据将永远不会发送,也不会被接收脚本读取。

放置此类数据的最佳位置是隐藏的输入字段。一种可能是使用带有方括号的名称,PHP会自动将其转换为数组。例如

<input type="text" name="email[value]">
<input type="hidden" name="email[magic]" value="true">

像这样填充一个数组:

$_POST['email']['value'] = '';
$_POST['email']['magic'] = 'true';

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章