提交按钮不会清除联系表单

时间:2015-02-18 23:00:04

标签: php html forms onclick contact-form

我仍然遇到联系表单的问题。如果您按提交按钮,邮件将被发送到我的邮箱,但表单字段不会清除/重置。我尝试过在网上找到很多不同的解决方案,比如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>';
    }
}
?>

1 个答案:

答案 0 :(得分:0)

替换此行

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