Jump to content

[SOLVED] List of errors in error message


Recommended Posts

Hello everyone,

I am new at PHP and am trying to create a feedback form.

I created it and it works fine but I have one problem, I want

the people who fill it out to be able to see what they forgot to fill out.

For example lets say im asking for name, phone number, email address, and message.

(in my real form im asking for a lot more but i didnt feel like typing the entire thing)

And lets say they forget to put their phone number and message,

I want them to see an error message that lets them know they forgot to put

their phone number and message. I've seen this done before so I know its possible,

can anyone let me know how?

thanks for reading,

bye.  :)

Link to comment
https://forums.phpfreaks.com/topic/55151-solved-list-of-errors-in-error-message/
Share on other sites

You could do something like this after the form is submitted:

 

<?php

//put all your POST data into short variables first, like the ones below...I left this part out for you =]

if (empty($name)) $errors[] = "You forgot to put your name!";
if (empty($phone)) $errors[] = "You forgot to put your phone number!";
if (empty($email)) $errors[] = "You forgot an email address!";
if (empty($message)) $errors[] = "You forgot a message!";

if (!empty($errors)){
echo "You had the following errors:<br>";
   foreach ($errors as $key => $val){
       echo '-'.$val.'<br>';
    }
} else {
   echo "You filled out the form successfully.";
}

?>

 

Not Tested.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.