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 6648361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:38:46+00:00 2026-05-26T00:38:46+00:00

I already got the form validation working, I just need to apply a CSS

  • 0

I already got the form validation working, I just need to apply a CSS class to the input field to give it a red border when an error was triggered. There are 2 possible errors. Each one works fine individually but when both errors are triggered only one of the boxes get the border. Used this same code on another form but not in a function and it worked fine. What am I missing?

//function stackoverflow($pet, $grab, $errors_NaN)
...
...
//testing here to make sure all errors are in the array
    var_dump($errors_NaN);
        echo '<br />';
        foreach($errors_NaN as $error){
            echo $error . '<br />';
        }


        echo '<div class="edit_col3">';
        echo '<div class="formrow">';
        echo '<label for="weight">Weight</label>'; //no text validation
            echo '<input ';


            if (!empty($errors_NaN)) {
                foreach($errors_NaN as $error){
                    if($error == 'weight_NaN'){
                        echo 'class="edit_mfwa"';
                                              //this triggers if ONLY weight_NaN is in the array but not if both weight_NaN and age_NaN
                    }
                    else {
                        echo 'class="weight"'; 
                    }
                }
            }
            elseif (empty($errors_NaN)){
                echo 'class="weight"';
            }


            echo ' type="text" name="weight" value="' . $grab['weight'] . '" id="weight" />';
            echo '<div class="pet_units">lbs</div>';
            echo '<div class="clear"></div>';
        echo '</div>';// end form row

        echo '<div class="formrow">';
        echo '<label for="age">Age</label>';  //no text validation
            echo '<input ';


            if (!empty($errors_NaN)) {
                foreach($errors_NaN as => $error){
                    if($error == 'age_NaN'){
                        echo 'class="edit_mfwa"';
                                              //this triggers properly in both situation
                    }
                    else {
                        echo 'class="age"';
                    }
                }
            } 
            elseif (empty($errors_NaN)) {
                echo 'class="age"';
            }


            echo ' type="text" name="age" value="' .  $grab['age'] . '" id="age" />';
            echo '<div class="pet_units">years</div>';
            echo '<div class="clear"></div>';
        echo '</div>'; //end form row

Commented in a few places where the problem seems to be happening

  • 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-26T00:38:47+00:00Added an answer on May 26, 2026 at 12:38 am

    If both weight_NaN and age_NaN are in your array, you will trigger both (so also using your else statement: echo ‘class=”weight”‘;

    I would say, if you use as following:

            $useClass = 'class="weight"';
    
            if (!empty($errors_NaN)) {
                foreach($errors_NaN as $error){
                    if($error == 'weight_NaN'){
                        $useClass 'class="edit_mfwa"';
                    }
                }
            }
    
            echo $useClass;
    

    It will work proper :)!

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

Sidebar

Related Questions

I got this HTML structure: <form> <input class=myTrigger type=radio value=1/> <input class=myTrigger type=radio value=2/>
I got this jQuery code which is working just fine. Except on element I
I got some trouble submitting a form with ajax. Since HTML5 Form already have
I've already got a NAnt build script that builds/runs tests/zips web project together, etc.
I've already got my custom header drawing in my GridView using SetRenderMethodDelegate on the
I'm setting up a Jabber server for my website. I've already got some user
A few times already, I got into situations where one of my SVN repository
I already know the obvious answer to this question: just download <insert favorite windows
I've got a simple form that enables users to enter a promotional code and
I've got a simple form on a User page that allows a User, once

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.