简体   繁体   中英

PHP form doesn't do anything

I know, that this is a often asked question, but I really can't find the problem. I have 3 contact forms on an homepage. They all have the same scripts. Two of them work perfect, but this one just doesn't do anything. And I really don't know why.

The markup:

<form action="contact.php" id="contactformmain" method="post" name="send" enctype="multipart/form-data">

        <div class="formular hidden animated">
                <div class="form-wrapper col-md-12 col-lg-12 col-xs-12">
                <h2 class="section-title-dark section-dosis header-distance min-distance-form-header"><span style="color:#ce5055;">Schicken Sie uns eine Nachricht:</span></h2>

                <i class="fa fa-3x fa-close close-form"></i>

                <span class="input-kontakt">
                <input class="input__field input__field--flat-form" type="text" id="k_name" name="k_name" required="required"/>
                <label class="input-label__me" for="k_name" required><span class="input__label-content input__label-content--haruki">NAME, Vorname</span></label>
                </span>

                <span class="input-kontakt">
                <input class="input__field input__field--flat-form" type="text" id="k_firma" name="k_firma" required="required"/>
                <label class="input-label__me" for="k_firma" required><span class="input__label-content input__label-content--haruki">FIRMA</span></label>
                </span>

                <span class="input-kontakt">
                <input class="input__field input__field--flat-form" type="tel" id="k_telefon" name="k_telefon" required="required"/>
                <label class="input-label__me" for="k_telefon" required><span class="input__label-content input__label-content--haruki">TELEFON</span></label>
                </span>

                <span class="input-kontakt">
                <input class="input__field input__field--flat-form email" type="text" id="k_email" name="k_email" required="required"/>
                <label class="input-label__me" for="k_email" required><span class="input__label-content input__label-content--haruki">E-MAIL</span></label>
                </span>

                <textarea class="requiredField message" id="k_message" name="k_message" placeholder="Message"></textarea>   



                <button id="submit_kontakt" class="kontakt-abschicken kontakt-button" type="submit" name="submit" >Absenden</button>
                <div class="sending-message small-centered column">
                <div id="message_post"></div>

                </div>

                </div>
        </div>

       </form>

PHP markup:

<?php
 $adminemail = "schroeder@exposedesign.de";

if ($_GET['send'] == 'comments')
{
$_ufirma = $_POST['k_firma'];                   
$_uname = $_POST['k_name'];
$_uemail = $_POST['k_email'];
$_number = $_POST['k_telefon'];
$_comments  =   stripslashes($_POST['k_message']);




$email_check = '';
$return_arr = array();

if($_uname=="" || $_uemail=="" || $_number=="" )
{
    $return_arr["frm_check"] = 'Fehler';
    $return_arr["msg"] = "Bitte füllen Sie alle essentiellen Felder aus.";
} 
else if(filter_var($_uemail, FILTER_VALIDATE_EMAIL)) 
{

$to = $adminemail;
$from = $_uemail;
$subject = "EXPOSÉDESIGN BUDGETPLANER";

$message =      '<h2 style="background-color: ACD086; padding:10px;">Eine neue Exposeanfrage:</h2>' . 
            'Name: &nbsp;&nbsp;' . $_uname . 
            '<br><br> Emailadresse:' . $_uemail . 
            '<br><br> Telefonnummer: &nbsp;&nbsp;' . $_number .  
            '<br><br> Firma:&nbsp;&nbsp;' . $_ufirma .
            '<br><br> Nachricht:&nbsp;&nbsp;' . $_comments .
            '<h2 style="background-color: ACD086; padding:10px;">Anfragedaten:</h2>' .
            '<br><br> Gesamtanzahl der Wohneinheiten: &nbsp;&nbsp;' . $q1a .
            '<br><br> Gesamtanzahl der Haustypen: &nbsp;&nbsp;' . $q2a .
            '<br><br> Standort des Projekts: &nbsp;&nbsp;' . $q4a.
            '<br><br> Quadratmeterpreis: &nbsp;&nbsp;' . $q5a.
            '<br><br> Zielgruppen: &nbsp;&nbsp;' . implode(',', $checkbox) .
            '<br><br> Gesamtwohnfläche: &nbsp;&nbsp;' . $q6a;

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "Nachricht von: " . $from . "\r\n";


} else {


$return_arr["frm_check"] = 'error';
$return_arr["msg"] = "Bitte geben Sie eine gültige Email-Adresse ein.";


}

echo json_encode($return_arr);
}

?>

jQuery markup:

$("#contactformmain").submit(function () {
    $("#submit-kontakt").value = 'Bitte warten...';

    $.post("contact.php?send=comments", $("#contactformmain").serialize(),
           function (data) {
            if (data.frm_check === 'error') {

                $("#k_message").html("<div class='errorMessage'>ERROR: " + data.msg + "</div>");
            } else {
                $(".formular").removeClass("fadeInLeftBig").addClass("fadeOutLeftBig");
                $("#contactformmain")[0].reset();
            }
        }, "json");
    return false;
    });

I just took the working forms, copy/pasted it and changed the id's and classes. I am not that good in forms and php, so it may be, that not everything is correct. But at least, the others are working...

That means, that I am working on a server, where php-scripts are working as they should. It must be a problem with the code.

When I click on the submit button, nothing really happens...

First of all, $("#submit-kontakt").value = 'Bitte warten...'; won't work since you're using a button, also, the jQuery syntax to change the value of an input is .val(...) not .value .

Try adding an alert to see if the form is correctly submitted before the $.post(...);

Also, as apokryfos said in the comment, you're not doing anything in your php script with the data, you're just setting the mail variables but not sending any mail. Neither in the php script nor the jQuery one.

I'd add alerts to start debugging and see if you receive any response from the scripts and how they are working. Or try using the programmer tools from Chrome / Edge / Firefox to track network requests.

Try using the below code. I am not sure whether this will work for you or not, but I guess your data is not been send through post request.

 $.post("contact.php?send=comments", {data:$("#contactformmain").serialize()},function (data) { if (data.frm_check === 'error') { $("#k_message").html("<div class='errorMessage'>ERROR: " + data.msg + "</div>"); } else { $(".formular").removeClass("fadeInLeftBig").addClass("fadeOutLeftBig"); $("#contactformmain")[0].reset(); } }, "json");

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