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

  • SEARCH
  • Home
  • 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 6356979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:04:33+00:00 2026-05-24T23:04:33+00:00

I am a new programmer and am attempting to do some validation for a

  • 0

I am a new programmer and am attempting to do some validation for a basic registration form. I have built a basic registration form that sends the user back to the same page when submitted. I have also created a user class and have created some basic validation functions. However, the functions have the error messages built into them. I obviously put the functions on the top of the registration form so when there is an error the errors are posted on the registration form. However, I have no control on how the error messages look and would like to know if there is a lot better way to somehow echo the error messages from outside the class so I can use some type of css or something else for better control of how they look. I hope that makes sense. Also when there is an error the user is sent back to an empty registration form. I was trying to figure out how to keep the valid information in the text boxes and just make them redo the invalid information. Here is a basic example of a validation I have done. I know its basic but I am very new to programming

function validate_password($password)
{   
    $valid = TRUE;
    if ($password == '')
    {
        echo "<p> Please enter a value for the password </p>";
            $valid = FALSE;
    }
    elseif($_POST['pwd'] !== $_POST['pwd2'])
        {
            echo "The passwords do not match please try again";
            $valid = FALSE;
        }
return $valid;
}
  • 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-24T23:04:35+00:00Added an answer on May 24, 2026 at 11:04 pm

    Don’t echo them right away, instead store them for later use. You mentioned this is inside a class, so you can use a class property to hold error messages.

    class YourClass
    {
    public $error;

    function validate_password($password)
    {   
        $valid = TRUE;
        if ($password == '')
        {
            // Set the error message
            $this->error = "Please enter a value for the password";
                $valid = FALSE;
        }
        // etc...
    }
    

    }

    Later, when you need to, you can output it in the HTML:

    if (!empty($yourclass->error)) {
      echo "<p class='errmsg'>{$yourclass->error}</p>\n";
    }
    

    You then just need a CSS class errmsg and you can style it how you like:

    .errmsg {
       color: #FF0000;
       font-size: 36px;
    }
    

    Now if you have that working, you can expand it further to make the $error class property into an array and push multiple messages onto it:

    // In the class, initialize it as an array
    $this->error = array();
    
    
    // Use the [] notation to append messages to the array.
    $this->error[] = "Another error message..."
    $this->error[] = "And yet another error message..."
    

    In your presentation code, use a loop to output the messages:

    // Output a big stack of error messages...
    foreach ($yourclass->error as $err) {
          echo "<p class='errmsg'>$err</p>\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a very new programmer, I have made a couple basic applications, however
New programmer- I have created a function to add a user to a database.
I am a very new programmer, and I have some trouble with the examples
I'm a new Windows programmer and I'm not sure where I should store user
We have 2 new GIS programmer/analyst in our department (new to programming and ArcObjects)
I am a new programmer... i have following problem.. Terminating app due to uncaught
Preface Let me start off by saying that I'm a relatively new programmer and
I am a new programmer in Python and I am trying to do some
hi i am a new programmer i have created an app of my own.
As a PHP programmer new to Perl working through 'Programming Perl', I have come

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.