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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:41:41+00:00 2026-06-08T09:41:41+00:00

hello i have the following problem: i have a form in that i would

  • 0

hello i have the following problem:

i have a form in that i would like to check via php for some input errors. beside that i would like to display an user information about whats being wrong.

the problem i have is, that i only like to display one message and not all at same time. therefor i need to filter all error messages from php to limit that to one.

so php is looking for this:

<?php if (isset($errors['for_a']):?><div id="errormessage">some text</div><?php endif; ?>

and the php rule is:

(case1) ... if ( isset($errors['for_a']) AND (!isset($errors['for_b'])) AND (!isset($errors['for_c'])) OR (!isset($errors['for_d'])) ...
OR
(case 2) ...AND (!isset($errors['for_b'])) AND (!isset($errors['for_c'])) AND (!isset($errors['for_d'])) ...
and so on for input field a...

so the problem is that i have 7 input fields and this would mean i have to write all possibilities. is there a way to shorten this?

thanks a lot.

UPDATE:

okay, maybe its not clear enough what i like to achieve.

i do not have problems displaying the error message. this works fine. each error message for each specific input field could be displayed correctly.

the problem is that i have different error messages for each of it. i do store that in a more dimensional array:

if(empty($a)){$errors['a'][]="first failure for a"}
if(something else happens($a)){$errors['a'][]="second failure for a"}
...

if(empty($b)){$errors['b'][]="first failure for b"}
if(something else happens($b)){$errors['b'][]="second failure for b"}
...

displaying that error messages is also not the problem.

<?php if (isset($errors['a'])):?>
<?php echo "<div class='erl'>"; 
echo $errors['a'][0];
echo "</div>";          
endif;?>
<?php endif;?>

the problem is the conditions for displaying only one error message at same time!

so here are some graphics to show what i mean:

this is the situation at the moment, all error divs will be displayed at the same time:

f0

this is what i like to achieve, that only one error message will be displayed at the same time start checking by the first input field:

f2

so that user will be forced to correct the first input field before displaying the second error layer:

f5

hope it gets clear now.

  • 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-06-08T09:41:44+00:00Added an answer on June 8, 2026 at 9:41 am

    I’m not sure what you’re asking. Usually with forms, if you have lots of fields you can create an array of errors, and either display the errors as a bullet list at the top of the form, or inline with its corresponding form element.

    <?php
    $errors = array();
    
    if (isset($_POST['submit'])) {
        // for each form field check it's valid, if it's not add a key to the errors array, i.e.
        if (empty($_POST['name'])) {
            $errors['name'] = 'Name is a required field';
        }
    }
    
    // display form
    ?>
    

    You’ll now have an $errors array. If it’s not empty, your form had errors. You can then display these errors in one of two ways. As a bullet list at the top of your form:

    <!DOCTYPE html>
    <html>
      <body>
        <form method="post">
    <?php if (!empty($errors)): ?>
          <p>Please correct the following errors:</p>
          <ul>
    <?php foreach ($errors as $error): ?>
            <li><?php echo $error; ?></li>
    <?php endforeach; ?>
          </ul>
    <?php endif; ?>
          <!-- the rest of your form -->
        </form>
      </body>
    </html>
    

    Or inline with each form field:

    <form method="post">
      <div class="input">
        <label for="name">Name:</label>
        <input type="text" name="name" id="name" />
    <?php if (isset($errors['name'])): ?>
        <div class="error"><?php echo $errors['name']; ?></div>
    <?php endif; ?>
      </div>
    </form>
    

    Hope that helps.

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

Sidebar

Related Questions

hello i have the following problem: i do check my form for some php
hello i have the following problem: i would like to create a filter for
Hello i have the following problem, I record a video using red5 like this:
I have the following problem: I would like to use footnotes together with the
I have some code in the form of a string and would like to
I have the following problem. Let's take the input (wikitext) ======hello((my first program)) world======
Hello Everything is right? My problem is the following: I have 3 tables: create
I have the following problem. I need to pass the hello function to name
Hello i have the following problem. I have a search page lets call it
I have the following in my controller: return render :js => alert('Hello Rails'); Problem

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.