我已经看到很多关于将 php 值放入 javascript 变量的问题,但是我还没有看到任何将 javascript 变量放入 php 变量的问题。所以我的问题是有没有办法做到这一点,如果有的话,你能帮助我,或者至少给我指明正确的方向。
到目前为止我的代码是这样的:
<script>
function CheckForm()
{
var inputElement = document.getElementsByTagName("input");
if((inputElement[0].value !=="first" && inputElement[0].value !=="") &&
(inputElement[1].value !=="Initial" && inputElement[1].value !=="") &&
(inputElement[2].value !=="last" && inputElement[2].value !=="") &&
(inputElement[3].value !=="someone@example.com" && inputElement[3].value !=="") &&
(inputElement[4].value !=="") &&
(inputElement[5].value !=="#" && inputElement[5].value !=="") &&
(inputElement[6].value !=="Lot" && inputElement[6].value !=="") &&
(inputElement[7].value !=="Evt. Name" && inputElement[7].value !=="") &&
(inputElement[8].value !=="xx/xx/xxxx" && inputElement[8].value !=="") &&
(inputElement[9].value !=="xx/xx/xxxx" && inputElement[9].value !=="") &&
(inputElement[10].value !=="xx:xx" && inputElement[10].value !=="") &&
(inputElement[11].value !=="") &&
(inputElement[12].value !=="xx:xx" && inputElement[12].value !=="") &&
(inputElement[13].value !=="") &&
(inputElement[14].value !=="") &&
(inputElement[15].value !=="") &&
(inputElement[16].value !=="x.xHours/Time Range" && inputElement[16].value !==""))
{
SendMail();
}
else
{
alert("One or more fields were not filled in correctly. Please try again.");
}
}
function GetBody()
{
var inputElement = document.getElementsByTagName("input");
var addInfo = document.getElementsByTagName("textarea");
var msg = "";
var line1= ("First Name: " + inputElement[0].value);
var line2= ("Middle Initial: " + inputElement[1].value);
var line3= ("Last Name: " + inputElement[2].value);
var line4= ("Email: " + inputElement[3].value);
//OTHER LINES OF MESSAGE HERE
msg = (line1 + "\n" + line2 + "\n" + line3 + "\n" + line4 + "\n" + line5 + "\n" + line6 + "\n" + line7 + "\n" + line8 + "\n" +
line9 + "\n" + line10 + "\n" + line11 + "\n" + line12 + "\n" + line13 + "\n" + line14 + "\n" + line15 + "\n" + line16 + "\n" +
line17);
return msg;
}
function SendMail()
{
var to = "someone@something.com"
var from = document.getElementsByTagName("input")[3].value;
var subject = "Parking Lot Request";
var msg = GetBody();
<?php
$to = "GET to";
$subject = "GET subject";
$message = "GET msg";
$from = "GET from";
$headers = "From: " . $from;
mail($to, $subject, $message, $headers);
mail($from, $subject, $message, $headers);
echo "Request has been sent. Also a copy has been sent to you.";
?>
}
</script>