简体   繁体   中英

Input value doesn't change after PHP script is added

Without the PHP script the value of the email address would automatically change after the studo number, functie and onderwijsinst values are entered, but as soon as I added the PHP script, the email value doesn't change anymore. The emailaddress needs to be automatically generated as shown in the jQuery code.

HTML code

<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 code (this was the quickest solution I could come up with)

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 code

<?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.
    }
?>

Fixed it; I had to change $("#email").val($studo_input + "@" + $tm); to $("#email").val($studo_input + "@" + $thomas more); I forgot I changed that option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM