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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:12:15+00:00 2026-05-23T09:12:15+00:00

I have created a form online and when the user clicks submit I want

  • 0

I have created a form online and when the user clicks submit I want the form to check for error (ie missing field). At the moment I have the form checking the fields one by one and as soon as it encounters a error it will exit without checking the rest of the fields. Is there any way I can combine all the if statements that check for errors into one.

Here is the code

 //Code to check that the Student Name field is completed
    if(empty($_POST['studentName'])) 
    {
    $studentNameError = "You did not enter the student name Wank";
    //echo "<h3> $studentNameError </h3>";
    exit();
    }
    //Code to check that the Tutor Name field is completed
    if(empty($_POST['tutorName'] ))
    {
    echo "<h3>You did not select a tutor name. Please go back and select your name from the tutors list</h3>";
    exit();
    }
    //Code to check that the Procedure field is completed
    if(empty($_POST['procedure'] ))
    {
    echo  "<h3>You did not select a procedure. Please go back and enter the name of the procedure which you undertook</h3>";
    exit();
    }
    //Code to check that the Grade field is completed
    if(empty($_POST['grade'] ))
    {
    echo "<h3>You did not select a grade. Please go back and select your grade from the drop down list</h3>";
    exit();
    }
    //Code to check that the Student Reflection field is completed
    if(empty($_POST['studentReflection'] ))
    {
    echo "<h3>The student did not enter any comments for this procedure. Student reflection is required for each procedure. Please go back and enter any comments</h3>";
    exit();
    }
    //Code to check if the tick box is checked that the tutor comment is entered

    if( !strlen($_POST['tutorComments']) && isset($_POST['alert'] ))
    {
        echo "<h3>You must enter a reason why you have clicked the alert box</h3>";
        exit();
    }
  • 1 1 Answer
  • 1 View
  • 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-23T09:12:16+00:00Added an answer on May 23, 2026 at 9:12 am

    For example, you can make a boolean variable to mark, if there is an error, and exit if it’s true + combine error messages into one

    $error = false;
    if(empty($_POST['studentName'])) 
    {
    $errorMessages[] = "You did not enter the student name Wank";
    $error = true;
    }
    //Code to check that the Tutor Name field is completed
    if(empty($_POST['tutorName'] ))
    {
    $errorMessages[] = "You did not select a tutor name. Please go back and select your name from the tutors list";
    $error = true;
    }
    //Code to check that the Procedure field is completed
    if(empty($_POST['procedure'] ))
    {
    $errorMessages[] = "You did not select a procedure. Please go back and enter the name of the      procedure which you undertook";
    $error = true;
    }
    //Code to check that the Grade field is completed
    if(empty($_POST['grade'] ))
    {
    $errorMessages[] ="You did not select a grade. Please go back and select your grade from the drop down list";
    $error = true;
    }
    //Code to check that the Student Reflection field is completed
    if(empty($_POST['studentReflection'] ))
    {
    $errorMessages[] = "The student did not enter any comments for this procedure. Student reflection is required for each procedure. Please go back and enter any comments";
    $error = true;
    }
    //Code to check if the tick box is checked that the tutor comment is entered
    
    if( !strlen($_POST['tutorComments']) && isset($_POST['alert'] ))
    {
        $errorMessages[] = "You must enter a reason why you have clicked the alert box";
        $error = true;
    }
    if($error)
    {
        echo("<h3>".implode('<br/>',$errorMessages)."</h3>");
        exit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an online PDF form which a user completes and then clicks a
I have created a form that contains fields used to accept a floating value
I have created a form <form name=form1 method=post> <textarea rows=5 cols=20 name=ta1></textarea> <input type=submit
Background: In Drupal 7, I have created a form with CCK (aka the Field
I have a form with dynamically created input fields - upon submitting it I
I have created a form with knockout that will allow the ability to give
I have created a form to upload a a newsletter into the database. I'm
I have created a form that is used for both adding and editing a
I have created a form with a dropdown list for 'Region'. Once the form
I have created a form for my news articles which I then call to

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.