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
  • 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-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 want to globalize my application. I have created a small form which asks
I have a form with 3 panels, the panels are created because at certain
I want to allow users to create their resume online. Resume creation will have
I have created online exam application (web based) in asp.net c#. In my application
I have created a form in my web application which has only a single
I have a namespaced controller for some admin functionality. My create form does not
I have a table of the form CREATE TABLE data { pk INT PRIMARY
I have a small form inside a table. POSTing that form creates a new
Is it possible to create a form on Windows using Ruby? I have a
Have created a c++ implementation of the Hough transform for detecting lines in images.

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.