在php中获取自定义属性值


get custom attribute value in 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浏览器不知道如何处理您的自定义属性,因此会忽略它。提交表单时发送的唯一数据是"success"元素的值。因此,您的自定义数据永远不会被发送,也永远不会被接收脚本读取。

将这些数据放入隐藏的输入字段是最好的地方。一种可能性是使用带有方括号的名称,PHP会自动将其转换为数组。例如

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

填充这样的数组:

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