Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中获取自定义属性值_Php_Attributes - Fatal编程技术网

在php中获取自定义属性值

在php中获取自定义属性值,php,attributes,Php,Attributes,我正在尝试使用使用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

我正在尝试使用使用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?
?>

//uploadform.php

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

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

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

您可以使用一些前端库(或原始JavaScript)来发布自定义属性,标准方式不允许您在$\u post数组中拥有自定义属性。此外,如果您像示例中那样发布表单,您将获得类似于$\u post['email']的内容,而不是您想要的$\u post['name']
mynewattribute=“表单中输入的值”
?@DevStan,我可以用get方法执行此操作吗?@Sebastian使用哪种方法并不重要
$_POST['email']['value'] = '';
$_POST['email']['magic'] = 'true';