如果没有PHP脚本,在输入studo编号,functie和onderwijsinst值后,电子邮件地址的值将自动更改,但是一旦我添加了PHP脚本,电子邮件值就不会再发生变化。需要自动生成emailaddress,如jQuery代码所示。
HTML代码
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-12">
<div class="form-group has-feedback" id="num">
<input type="text" required pattern="[a-z]{1}[0-9]{7}" name="studo_number" id="studo_number" class="form-control input-lg" placeholder="Student/docent nummer" tabindex="4" maxlength="8" title="Nummer moet beginnen met 1 kleine letter en 7 cijfers">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="form-group has-feedback" id="fun">
<select class="form-control input-lg" name="functie" id="functie" required>
<option value="" disabled selected>Functie</option>
<option value="student">Student</option>
<option value="docent">Docent</option>
</select>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="form-group has-feedback" id="ond">
<select class="form-control input-lg" name="onderwijsinst" id="onderwijsinst" required>
<option value="" disabled selected>Onderwijsinstelling</option>
<option value="thomas more">Thomas More</option>
<option value="hik">CVO</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-12">
<div class="form-group">
<input type="email" name="email" id="email" class="form-control input-lg" placeholder="E-mailadres" tabindex="5" disabled required>
</div>
</div>
</div>
jQuery代码(这是我能提出的最快的解决方案)
jQuery(function (){
setInterval(function() {
var $studo_input = $("#studo_number").val();
var $functie_input = $("#functie").val();
var $onderw_input = $("#onderwijsinst").val();
var $hik = "hik.be";
var $tm = "thomasmore.be";
var $student = "student.";
if($studo_input !== "" && $functie_input !== "" && $onderw_input !== ""){
if($functie_input === "student"){
if($onderw_input === "hik"){
$("#email").val($studo_input + "@" + $hik);
}
else if ($onderw_input === "tm"){
$("#email").val($studo_input + "@" + $student + $tm);
}
}
else if($functie_input === "docent"){
if($onderw_input === "hik"){
$("#email").val($studo_input + "@" + $hik);
}
else if($onderw_input === "tm"){
$("#email").val($studo_input + "@" + $tm);
}
}
}
else if($studo_input === "" || $functie_input === "" || $onderw_input === ""){
}
},500);
});
PHP代码
<?php
if(isset($_POST['submit'])){
$to = "mail@mail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$sur = $_POST['surname'];
$lname = $_POST['last_name'];
$username = $_POST['display_name'];
$studonr = $_POST['studo_number'];
$funct = $_POST['functie'];
$onderw = $_POST['onderwijsinst'];
$voorw = $_POST['t_and_c'];
$subject = "Registratie aanvraag";
$subject2 = "Kopie van je registratie aanvraag";
$message = "GEBRUIKERSNAAM: " . $username . "\n" . "VOORNAAM: " . $sur . "\n" . "ACHTERNAAM: " . $lname . "\n" . "STUDENT/DOCENT NUMMER: " . $studonr . "\n" . "FUNCTIE: " . $funct . "\n" . "ONDERWIJSINSTELLING: " . $onderw . "\n" . "EMAIL ADRES: " . $from . "\n" . "GAAT AKKOORT MET DE ALGEMENE VOORWAARDEN & HET HUISHOUDELIJK REGLEMENT: " . $voorw ;
$message2 = "Hier is een kopie van je gegevens: \n\n" . "GEBRUIKERSNAAM: " . $username . "\n" . "VOORNAAM: " . $sur . "\n" . "ACHTERNAAM: " . $lname . "\n" . "STUDENT/DOCENT NUMMER: " . $studonr . "\n" . "FUNCTIE: " . $funct . "\n" . "ONDERWIJSINSTELLING: " . $onderw . "\n" . "EMAIL ADRES: " . $from . "\n" . "GAAT AKKOORT MET DE ALGEMENE VOORWAARDEN & HET HUISHOUDELIJK REGLEMENT: " . $voorw ;
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $sur . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
答案 0 :(得分:0)
修正了它;我不得不将$("#email").val($studo_input + "@" + $tm);
更改为$("#email").val($studo_input + "@" + $thomas more);
我忘记了我更改了该选项。