簡體   English   中英

提交按鈕不會清除聯系表單

[英]Submit button doesn't clear contact form

我仍然有聯系表的問題。 如果按提交按鈕,則郵件將發送到我的郵箱,但是表單字段不會清除/重置。 我嘗試了很多在Web上找到的不同解決方案,例如onClick-events,但對我來說真的沒有用。 它必須全部由提交按鈕決定...此外,收件人的“姓名,主題和郵件”不會轉發到我的郵箱:(

誰能幫我嗎?

謝謝你的幫忙!

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();">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM