<form id="test" method="post" action="getValue.php">
<input type="submit" name="sample" value="A" customizedValue1="1" customizedValue2="X"/>
<input type="submit" name="sample" value="B" customizedValue1="2" customizedValue2="Y"/>
</form>
我想知道如何通过使用php获取上面几个单选按钮之间的自定义属性的值。
如何在php中获取customizeValue1和customizedValue2的值?
由于
答案 0 :(得分:1)
您无法直接从PHP访问此值,您需要将它们作为AJAX POST
值传递给PHP文件,如下所示:
<强> FORM 强>
<form id="test" method="post" action="getValue.php">
<input type="radio" name="sample" value="A" customizedValue1="1" customizedValue2="X"/>
<input type="radio" name="sample" value="B" customizedValue1="2" customizedValue2="Y"/>
<button type="submit"> Submit </button>
</form>
<强> JS 强>
$('#test').on('submit',function(){
var customizedValue1 = $('#test input[name=sample]:checked').attr('customizedValue1');
$.post('getValue.php',{'customizedValue1':customizedValue1});
});
在 getValue.php 上,您可以访问以下值:
echo $_REQUEST['customizedValue1'];
答案 1 :(得分:0)
如果他们以某种方式相互连接。您还可以将值用作html格式的数组
<form id="test" method="post" action="getValue.php">
<input type="text" name="data[A][customizedValue1]" value="value1" />
<input type="text" name="data[A][customizedValue2]" value="value2" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if(isset($_POST['submit'])){
$customizedValue1 = $_POST['data']['A']['customizedValue1'];
$customizedValue2 = $_POST['data']['A']['customizedValue2'];
echo $customizedValue1;
echo $customizedValue2;
}
?>