How to make an error-popup message after submitting a form?


First of all, I am not sure if I post this in the correct sub-forum, and if that is the case, I apologize and ask that the thread is moved to the correct category.

Anyway. I am pretty new with web design, and I am currently learning about the subject on high school. We work on software that is a bit outdated (Adobe CS3), but I still like doing it. As for web design, we use WAMP server, Dreamweaver CS3, MySQL Query Browser and PHP. I do, however, know little to nothing about coding in PHP, I just kind of know what it’s for. I know how to make a functioning web page, how to create databases and connect them to the web page, and how to show these databases through a dynamic web page, but little else.

So the thing I am trying to do now is that after using an “Record Insertion Form Wizard” in Dreamweaver CS3 (to which I’ve already made a database, a query and so on), I want two different popup messages to come after clicking “submit form”, both one confirming that the entire process was successful, and one saying that the user entered invalid information. I already know how to do the former, by going under Tag <input>, behaviors, clicking the plus-sign, clicking popup message and then just writing the message and hitting “OK”. But how do I make a seperate one for if the submission failed? And is it possible if this box automatically tells the user exactly what went wrong?

hmm, I think you should use javascript.

attach onsubmit event, then do evaluation of the form content

something like that:

<!DOCTYPE html>
<html xmlns="">
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function executeOnSubmit()
        var status = checkField();

        if(status[0] == 0)
                return false;

        var res = confirm("Submit the form contents?");

                return true;
                return false;

function checkField()
        var check = new Array();
        var elemValue = document.getElementById("name").value;
        if(elemValue == "") {
                check[0] = 0;
                check[1] = "Enter something!!!";
        else if (elemValue = "1") {
                check[0] = 0;
                check[1] = "You entered 1!! How dare you?!!";
        else {
                check[0] = 1;
        return check;


<form action="test.php" method="post" onsubmit="return executeOnSubmit();">
<label>Name</label><input type="text" name="name" size="20" id="name" />
<input type="submit" name="submit" value="submit" />

with this you will get alerts when user don’t enter anything, and different alert when user input was “1”.

Thanks for the help, but since I am doing this in school, I think I am supposed to do stuff like this in PHP (if at all possbible). I don’t even know if it is possible to use both javascript and PHP in one site. So if you have a PHP-solution, that would be great.

PHP is an server-side scripting language, that means that to check if a user made a mistake or if he completed a form correctly, has to be always done on the server.
What you can make is a php page which is both the form and the validation of the page. In that way it looks like you will never leave the page but in fact you leave the page to exact the same page.
Makes any sense?

Otherwise the only solution is a javascript solution like boatmark said.

Of course it is possible. Javascript is client-side and php is server-side.

The problem is - you CAN’T create popup with php. You can do all logic in php, but alerts must be created with javascript.

for php solutiuon:

this is your form:

<form action="index.php" method="POST" enctype="multipart/form-data">  
    <input class="form" type="text" name="title"/>  
    <textarea class="form" name ="textentry" rows="3"></textarea>  
    <input type="hidden" name="submitted" value="1">  
    <input type="submit" value="Submit"/>  

Note input field with type=“hidden”. It’s important. with it we will check if form was already submitted, or not.
like this:

if ($_POST['submitted']==1) {  

Also action=“index.php” - index.php is actually the page where the form is.

and next we will add some validation:

if ($_POST['submitted']==1) {  
    $errorMsg = ""; // error messages variable  
    if (!empty($_POST['title'])){  // check if title was entered
        $title = $_POST['title']; 
        $errorMsg = "You must enter title";  // and if not - add error message
    if ($_POST['textentry']){  // check if content was entered 
        $textentry = $_POST['textentry'];  
        if (!empty($errorMsg)){ // if there is already an error, add next error  
            $errorMsg = $errorMsg . " & content";  
            $errorMsg = "You must enter content";  
    if (!empty($errorMsg)){ // if there is errors display them
        echo ' <script type="text/javascript">
As you can see we display errors with javascript popup at the end. 


I am not familiar with Dreamweaver CS3, so I can’t really answer your question, but I did a quick google search and found these results:

The Essential Guide to Dreamweaver CS4 With CSS, Ajax, and PHP