如何张贴一个选择类的php邮件脚本的地方的值?



我希望从一个选择选项张贴类名或文本,但不是值。

该值用于拉出页面上其他地方使用的价格,但我需要在电子邮件中包含来自选择的类或文本。

形式
<form method="post" id="my-form" action="emailscript.php" form enctype="multipart/form-data">
<select name="signMaterial" id="signMaterial" class="signMaterial" onchange="updateSignMaterial(); updateSignMaterialClass();">
<option value="111" class="Black-Riven-Slate" >Slate - Italian Black (Riven)</option>
<option value="222" class="Black-Honed-Slate" >Slate - Italian Black (Honed)</option>
<option value="333" class="Black-Polished-Granite" >Granite - Black Polished</option>
<option value="444" class="Green-Honed-Slate" >Green Hones Slate</option>
</select>

emailscript

$signMaterial = $_POST['signMaterial'];
$message .= "<tr><td><strong>Sign Material:</strong></td><td>".$signMaterial."</td></tr>";

有没有人知道如果这是可能的,我已经尝试过数据类无效

$signMaterialClass = $_POST['signMaterial']['data-class'];

不能在PHP端访问HTML类。表单提交的结果是只包含表单值的HTTP请求。你可以有隐藏的HTML输入,其中你可以在select中插入选项的类名。

请注意,我的JS技能是过时的,可能有更好的方法来做到这一点。

window.onload = function() {
var theSelect = document.getElementById("theSelect");
var theClassOfSelect = document.getElementById("theClassOfSelect");
theSelect.addEventListener('change', function handleChange(event) {
theClassOfSelect.value = theSelect.options[theSelect.selectedIndex].className;
});
}
<form method="post">
<select name="theSelect" id="theSelect">
<option value="111" class="classnameone">Example Option #1</option>
<option value="222" class="classnametwo">Example Option #2</option>
</select>
<input type="hidden" name="theClassOfSelect" id="theClassOfSelect" />
</form>