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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:10:46+00:00 2026-05-15T18:10:46+00:00

I have an HTML form that takes inputted data and sends it via the

  • 0

I have an HTML form that takes inputted data and sends it via the mail() function. I also have some validation techniques that validate the inputs, and I created an array variable $errors to log all of the errors; for example,

if the name was left empty, $errors[]=”Name empty”;
If the email was left empty, $errors[]=”email empty”;

and so on..

I was able to report the errors using the following technique:

print '<div id="formfeedback"><h3>Error!</h3><p>The following error(s) has occurred:<br />';
    foreach ($errors as $msg) { //prints each error
            print " - $msg<br />\n";
        } // end of foreach

However, what I want is the following. I want the page to be redirected back to the original form that was used to input the information (I know the exact link location, so i can use a header() or even a <meta=http-equiv=refresh> to bring me back to the form page.

Also, on the form, I want to be able to post the errors above the form in some div (call it div=errors)

Would I be able to do the following?

    <div id="errors">
<?php    
print 'The following error(s) has occurred:<br />';
            foreach ($_REQUEST[$errors] as $msg) { //prints each error
                    print " - $msg<br />\n";
                } // end of foreach
?>   
 </div>

Thanks a lot!

Amit

  • 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-15T18:10:47+00:00Added an answer on May 15, 2026 at 6:10 pm

    I agree with @Fosco. I want to explain a little bit more-

    There may be two cases-
    1. You are doing raw php
    2. You are coding on any php framework like CI or your own.

    and this will help to identify error field and change style to make better user response. Also last input data remain as it was.

    1. You are doing raw php
      In this case you can receive the input data in same file/page.
      I will do a common example later.

    2. You are coding on any php framework like CI or your own.
      In this case you load a view file to show the form page and you can pass data to view page/file when you load it.

    For both of above case you can do some coding like-

    /* 
    your input validation and verification goes here. where $error is generated too
    In addition add some error status in above section, 
    you can do it in your $error array too. Also you store received data into $data here. index of $data should be similar as (corresponding) HTML input name. 
    You can do it like below
    */
    $error_stat = array();
    //if the input field name is "email" and email input data raises any error then
    
    $error_stat['email'] = true;
    // same for name
    $error_stat['name'] = true;
    // and so on
    
    // now decide whether you will back to the form page or send the email and do other tasks
    if(count($error_stat)<= 0){
      // send email
      // do aditional tasks
    }
    else{
      // load the form again if its aframework or the form is in seperate file
      // off course send $error,$data and $error_stat to the form page/file
    }
    
    // now here is a code segment of form page
    <?php if(isset($error) && count($error)>0):?>
    <div id="error-msg">
    <?php
    //display errors here
    ?>
    </div>
    <?php endif;?>
    
    <form .... >
    <input type="text" name="email" class="<?php echo (isset($error_stat['email'])?'error':'else'); ?>" value="<?php echo $data['email'];?>" />\
    <!-- and so on ... -->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.