首先:我正在使用 Jeffrey Way 在 In the Woods 中制作的邮件脚本。
我有一个简单的表格,如下所示:
<form method="post" action="sendEmail.php" id="form_reserveren">
<div id="container">
<div id="main" style="width: 100%; height: auto; float: left;">
<div class="left">
<h3>Uw gegevens</h3>
<p style="margin-bottom: 30px; height: 40px; width: 100%;">
<input type="radio" id="zml_geslacht" name="zml0" value="de Heer"/><span style="float: left; margin-top: -5px; height: 25px;">de Heer</span><br />
<input type="radio" id="zml_geslacht" name="zml0" value="Mevrouw"/><span style="float: left; margin-top: -5px; height: 25px;">Mevrouw</span>
</p>
<p>
<input type="text" id="zml_voornaam" name="zml1" value="Uw voornaam" onblur="if(this.value=='') this.value='Uw voornaam';" onfocus="if(this.value=='Uw voornaam') this.value='';"/>
<input type="text" id="zml_achternaam" name="zml2" value="Uw achternaam *" onblur="if(this.value=='') this.value='Uw achternaam *';" onfocus="if(this.value=='Uw achternaam *') this.value='';"/>
</p>
<p>
<input type="text" id="zml_email" name="zml3" value="Uw e-mailadres *" onblur="if(this.value=='') this.value='Uw e-mailadres *';" onfocus="if(this.value=='Uw e-mailadres *') this.value='';"/>
</p>
</div>
<div class="right">
<h3>Uw reservering</h3>
<p style="height:68px;">
<textarea name="zml13" id="zml_opmerkingen" rows="12">Opmerkingen</textarea>
</p>
<p><input type="submit" name="submit" id="submit" value="Email Us!" /></p>
<ul id="response" />
</div>
</div><!--end main -->
</div><!-- end container -->
</form>
这通过ajax,如下所示:
var zml0 = $('input#zml_geslacht').html( $(':checked').val());
var zml1 = $('input#zml_voornaam').val();
var zml2 = $('input#zml_achternaam').val();
var zml3 = $('input#zml_email').val();
var zml13 = $('textarea#zml_opmerkingen').val();
$.ajax({
type: 'post',
url: 'sendEmail.php',
data: 'zml0=' + zml0 + '&zml1=' + zml1 + '&zml2=' + zml2 + '&zml3=' + zml3 + '&zml13=' + zml13,
success: function(results) {
$('#main img.loaderIcon').fadeOut(1000);
$('ul#response').html(results);
}
}); // end ajax
之后它转到我的 sendEmail.php 以将表单发送到电子邮件地址(并将其存储在数据库中)。查询是:
$zml0 = $_REQUEST['zml0']; // Geslacht
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// query
$sql = "INSERT INTO test (zml0,zml1,zml2) VALUES (:zml0,:zml1,:zml2)";
$q = $conn->prepare($sql);
$q->execute(array(':zml0'=>$zml0,
':zml1'=>$zml1,
':zml2'=>$zml2));
一切正常。我还有姓名、电子邮件地址等,除了 Gender 单选按钮(荷兰语中的 Gender 是 Geslacht,我将其命名为 zml0 以更好地防止垃圾邮件发送者)。当然,这个想法是用户应该选择女性或男性。
当它存储在数据库中时,它所说的只是[object Object]。另外,当我只是回显输入时。我怎样才能使这项工作?