Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.