简体   繁体   中英

Submit button doesn't clear contact form

I still have a problem with a contact form. If you press the submit button, the message is being sent to my mailbox, but the form fields don't clear/reset. I've tried a lot of different solutions found on the web like onClick-events but nothing really worked for me. It must all be up to the submit-button… Furthermore "name, subject and mail" of the addressee are not forwarded to my mailbox :(

Could anyone please help me?

Thanks a lot for your support!

HTML:

    <div class="seven columns bigpadding" data-role="form">
        <h3 class="extrabold blacktext midbottommargin">Ich freue mich über Ihre Nachricht.</h3>
        <p class="meta">
            Bitte füllen Sie die nachfolgenden Felder aus. <br> Ich werde mich schnellstmöglich bei Ihnen melden.
        </p>
        <form method="post" action="sendemail.php" id="contactform">
            <div class="row">
                <dl class="field eight columns">
                    <dd><label for="name">Name*</label></dd>
                    <dt class="text"><input type="text" name="name" id="name"/>
                    </dt>
                    <dd class="msg">Da lief was schief :-(.</dd>
                </dl>
            </div>
            <div class="row">
                <dl class="field eight columns">
                    <dd><label for="email">E-mail*</label></dd>
                    <dt class="text"><input type="text" name="email" id="email"/>
                    </dt>
                    <dd class="msg">Da lief was schief :-(</dd>
                </dl>
            </div>
            <div class="row">
                <dl class="field eight columns">
                    <dd><label for="subject">Betreff</label></dd>
                    <dt class="text"><input type="text" name="subject" id="subject"/>
                    </dt>
                    <dd class="msg">Da lief was schief :-(</dd>
                </dl>
            </div>
            <dl class="field row">
                <dd><label for="message">Ihre Nachricht*</label></dd>
                <dt class="textarea">
                <textarea name="message" id="message"></textarea></dt>
                <dd class="error msg">Da lief was schief :-(</dd>
            </dl>
            <div class="row">
                <input class="submit three columns" type="submit" value="Abschicken" id="submit"/>
            </div>
        </form>
        <!-- END FORM -->
        <div class="row midpadding" id="success">
        </div>
    </div>

PHP:

<?php

ini_set ( 'display_errors', true ); 

define("CONTACT_EMAIL", 'test@test.com');

function ValidateEmail($email)
    {
    $regex = '/([a-z0-9_.-]+)'. # name

    '@'. # at

    '([a-z0-9.-]+){2,255}'. # domain & possibly subdomains

    '.'. # period

    '([a-z]+){2,10}/i'; # domain extension 

    if($email == '') { 
            return false;
        }
        else {
            $eregi = preg_replace($regex, '', $email);
    }

    return empty($eregi) ? true : false;
} // end function ValidateEmail



error_reporting (E_ALL ^ E_NOTICE);

$post = isset( $_POST['name'] );  

if($post) {
    //include 'functions.php';

    $name = stripslashes($_POST['name']);
    $email = trim($_POST['email']);
    $subject = stripslashes($_POST['subject']);
    $message = stripslashes($_POST['message']);

    $error = '';

    if(!$name) {
        if (!$error) $error .= '<p><ul style="list-style:none;">';
        $error .= '<li>Bitte geben Sie Ihren Namen ein.</li>';
    }
    if(!$email) {
        if (!$error) $error .= '<p><ul>';
        $error .= '<li>Bitte geben Sie eine gültige E-Mail Adresse ein.</li>';
    }

    if($email && !ValidateEmail($email)) {
        if (!$error) $error .= '<p><ul>';   
        $error .= '<li>Bitte geben Sie eine gültige E-Mail Adresse ein.</li>';
    }

    if(!$message) {
        if (!$error) $error .= '<p><ul>';   
        $error .= "<li>Bitte geben Sie eine Nachricht ein.</li>";
    }


        if(!$error) {
        $mail = mail(CONTACT_EMAIL, $subject, $message,"X-Mailer: PHP/" . phpversion());


        if($mail) {
            echo '<h6>Vielen Dank für Ihre Nachricht. Ich werde mich<br>so schnell wie möglich bei Ihnen melden.</h6>';
        } else {
            echo '<div class="notification_error">Da lief was schief! :-(</div>';
        }

    }
    else
    {
        $error .= '</ul></p>';
        echo '<div class="notification_error">'.$error.'</div>';
    }
}
?>

替换此行

<form method="post" action="sendemail.php" id="contactform" onsubmit="this.reset();">

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