Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7522579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:33:47+00:00 2026-05-30T02:33:47+00:00

My form gives me a success message when all required fields are filled and

  • 0

My form gives me a success message when all required fields are filled and i click send.
But no error message or success message when a field is missing. Anyone spot the error?
I have no idea about PHP so be kind!

Please help, I need this by tomorrow!

<?php

function died($error) {
    // your error code can go here
    echo "Wir freuen uns sehr leid, aber es gab Fehler(s) mit dem Formular, das Sie   vorgelegt gefunden. ";
    echo "Diese Fehler werden unten angezeigt.<br /><br />";
    echo $error."<br /><br />";
    echo "Bitte gehen Sie zurück und diese Fehler zu beheben.<br /><br />";
    die();
 }


if(!empty($_POST['email'])) {

    // CHANGE THE TWO LINES BELOW
    $email_to = "xxxx@xxx.xxx";
    $email_subject = "Nachricht von Website Kontaktformular";


    // validation expected data exists
    if(empty($_POST['vorname']) || empty($_POST['nachname']) || empty($_POST['email']) || empty($_POST['nachricht'])) {
        died('Es tut uns leid, aber es scheint ein Problem mit dem Formular, das Sie vorgelegt werden.');       
    }

    $vorname = $_POST['vorname']; // required
    $nachname = $_POST['nachname']; // required
    $email_from = $_POST['email']; // required
    $email = $_POST['email']; // geändert
    $telefon = $_POST['telefon']; // not required
    $nachricht = $_POST['nachricht']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'Die Email Adresse, die Sie eingeben, nicht gültig zu sein scheint.<br />';
    }
    $string_exp = "/^[A-Za-z .'-]+$/";


    if(!preg_match($string_exp,$vorname)) {
        $error_message .= 'Die Vorname Sie eingeben, nicht gültig zu sein scheint.<br />';
    }
    if(!preg_match($string_exp,$nachname)) {
        $error_message .= 'Die Nachname Sie eingeben, nicht gültig zu sein scheint.<br />';
    }
    if(strlen($nachricht) < 2) {
        $error_message .= 'Die Nachricht, die Sie eingeben, nicht gültig zu sein scheint.<br    />';
    }
    if(strlen($error_message) > 0) {
        died($error_message);
    }
    $email_message = "Formular einzelheiten unten.\n\n";

    function clean_string($string) {
        $bad = array("content-type","bcc:","to:","cc:","href");
        return str_replace($bad,"",$string);
    }

    $email_message .= "Vorname: ".clean_string($vorname)."\n";
    $email_message .= "Nachname: ".clean_string($nachname)."\n";
    $email_message .= "Email: ".clean_string($email)."\n";
    $email_message .= "Telefon: ".clean_string($telefon)."\n";
    $email_message .= "Nachricht: ".clean_string($nachricht)."\n";


    // create email headers
    $headers = 'From: '.$email."\r\n".
        'Reply-To: '.$email."\r\n" .
        'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);  
    ?>

    <!-- place your own success html below -->
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
        <p style="font-size:1.125em; font-family:Arial, Helvetica, sans-serif; background-color:#a6bf48; margin-top:90px; text-align:center; margin-left:auto; margin-right:auto; width:960px; padding:20px;">
            Vielen Dank für ihre Nachricht! Ich werde mich sobald wie möglich mit ihnen in Verbindung setzen.<br><br>
            <a href="psychologin.html" style="color:#FFF">Zurück</a>
        </p>
    </body>
    </html>

    <?php
}
die();
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:33:48+00:00Added an answer on May 30, 2026 at 2:33 am

    At first glance, if you don’t fill the email text field, then nothing will appear what-so-ever, so you have that in the wrong place – try changing it from:

    if(!empty($_POST['email'])){
    

    To:

    if(isset($_POST)){
    

    Update

    Further more, upon tiding up your code, you have written died() a few times – this should be die()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to display error message in popup and if success message comes hide all
I have a contact form in my flash file with name/email/message fields which a
I need the intPtr for a form. Control.FromHandle(control) gives me the control from a
Is there a way to give a form a special error rendering function in
I am sure this has been asked already, but I have been trying all
i'm digging more and more into Zend_Framework, but finding good resources isn't all too
For a given form in a database, is there a quick/easy way to find
I've created two UserControls, a ValidationManager and a ValidationOutput. On a given form there
Given some typical search form, I can't construct this form action when submitting a
Given the following HTML form: <form id=myform> Company: <input type=text name=Company value=ACME, INC./> First

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.