我有一个HTML表单,从复选框检索某些选项:发送Javascript数组在邮件
<form action="" method="post" id="menuform" name="menuform">
<fieldset>
<legend>Select a Menu</legend>
<label>
<input type="radio" name="selectedmenu" checked value="menu01" ape-qty='8' ent-qty='1' pes-qty='1' sor-qty='1' car-qty='1' pos-qty='1' data-price='95' />
<span>First Item</span>
</label>
...(more)...
</fieldset>
<fieldset>
<legend id='aperitivosPrompt'>Elegir Aperitivos</legend>
<label>
<input type='checkbox' name='aperitivos' value="1" />
<span>Item 1</span>
</label>
<label>
<input type='checkbox' name='aperitivos' value="2" />
<span>Item 2</span>
</label>
<label>
<input type='checkbox' name='aperitivos' value="3" />
<span>Item 3</span>
</label>
...(more)...
</fieldset>
<fieldset>
<input type="submit" value="Enviar" />
</fieldset>
</form>
然后我送这个变量的JavaScript文件,我保存所有复选框选项在多个阵列
var menuform = document.getElementById('menuform'),
radios = document.getElementsByName('selectedmenu'),
aperitivos = document.getElementsByName('aperitivos'),
aperitivosPrompt = document.getElementById('aperitivosPrompt'),
totalPrice = document.getElementById('totalPrice'),
result = document.getElementById('result'),
aperitivosAllowed = 0,
currentSelectionAperitivos = [],
currency = '€';
function handleAperitivos(e) {
var count = getSelectedCountApe();
if (count > aperitivosAllowed) {
resetSelectApe();
} else {
currentSelectionAperitivos = getSelectedValuesApe();
}
}
...(more)...
function getSelectedCountApe() {
var count = 0;
for (var i = 0; i < aperitivos.length; i++) {
if (aperitivos[i].checked) count++;
}
return count;
}
...(more)...
那么,如何在电子邮件中发送这些名为currentSelectionAperitivos = []
的阵列呢?我希望在用户选择所有选项后,我会在收件箱中收到一封电子邮件,其中包含选定的选项。
我认为我必须连接此表格和JS
文件与PHP
函数,并从那里发送电子邮件。无论如何,我该如何做到这一点?
-EDITED-
我试图用JSON的解决方案:
for (var i = 0; i < aperitivos.length; i++) {
var item = {
"valor": i,
"etiqueta": aperitivos[i].value
};
currentSelectionAperitivos.push(item);
}
currentJSON = JSON.stringify({currentSelectionAperitivos:currentSelectionAperitivos});
console.log(currentJSON);
所以现在我在浏览器控制台中看到所有的 “值” 从田地HTML表单的<input>
。但不仅CHECKED值,而且我现在需要的是获取此JSON.stringify并通过邮件使用PHP发送它。
正在处理表单的php在哪里? – jeroen
研究如何通过电子邮件发送表格数据与PHP –
签出phpmailer。其中一个最简单的PHP电子邮件插件那里https://github.com/PHPMailer/PHPMailer –