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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:06:53+00:00 2026-06-06T19:06:53+00:00

My form is working fine with the validations being done by PHP. I have

  • 0

My form is working fine with the validations being done by PHP.
I have three fields: Name, EMail and Message.
Form and PHP code is within the same pgae, same page is called for validations when user submits the form.

When a user submits the form, same page is called and it checks whether the form is submitted or not.
If the form is submitted it then does the validations for blank entries and throws error message below the fields to inform user that field is left blank. It also shows error icon next to field.

Till this, it is working fine.

However, the problem, is if the user has filled any field, for example name filed and left the other two fields(EMail and Message) blank, then on submittion, it throws error messages for blank fields which is ok, but for name field which was filled by user it empty the content and shows blank name field and does not show error(as earlier user had filled it).

My only concern is that when it relods the form after submission, it should also reload the earlier values in the respective fields which user input before submitting.

Below is the PHP validation code.

<?php
error_reporting(E_ALL & ~E_NOTICE);

    if(isset($_POST['nameField_Name']) AND isset($_POST['nameField_EMail']) AND isset($_POST['nameField_Message']) AND isset($_POST['nameSubmit'])){  
        // Form Submited  
        if ($_POST['nameField_Name']) {
    $phpVarNameField = mysql_escape_string($_POST['nameField_Name']);
} else {
    $errormsgNameField = "Name field is required, Please enter your Name.";

}

if ($_POST['nameField_EMail']) {
    $phpVarEMailField = mysql_escape_string($_POST['nameField_EMail']);
} else {
    $errormsgEMailField = "E-Mail field is required, Please enter your E-Mail ID.";
}

if ($_POST['nameField_Message']) {
    $phpVarMessageField = mysql_escape_string($_POST['nameField_Message']);
} else {
    $errormsgMessageField = "Message field is required, Please enter your Message.";
}
    }  
?>

Below is the form code.

                <form name="myform" action="contactus.php" method="post"">
                <div id="r1">
                    <div id="r1c1">
                        <input type="text" name="nameField_Name" id="idField_Name" placeholder="Enter your name here"/>
                    </div>
                    <div id="r1c2">
                 <?php  
                      if(isset($errormsgNameField)){  // Check if $msg is not empty  
                  echo '<img src="error.png" width="45" height="45" style="margin: 5px 0px" alt="">';
                      }  
                    ?> 
                    </div>
                </div>
                <div id="afterr1">
               <?php  
                      if(isset($errormsgNameField)){  // Check if $msg is not empty  
                  echo '<div class="statusmsg" id="idErrorMsgNameField">'.$errormsgNameField.'</div>'; // Display our message and wrap it with a div with the class "statusmsg".  
                      }  
                    ?>  

                </div>
                <div id="r2">
                    <div id="r2c1">
                        <input name="nameField_EMail" type="text" id="idField_EMail" placeholder="Enter your E-Mail address here" />
                    </div>
                    <div id="r2c2">
                <?php  
                      if(isset($errormsgEMailField)){  // Check if $msg is not empty  
                  echo '<img src="error.png" width="45" height="45" style="margin: 5px 0px" alt="">';
                      }  
                    ?> 
                    </div>
                </div>
                <div id="afterr2">
                <?php  
                      if(isset($errormsgEMailField)){  // Check if $msg is not empty  
                  echo '<div class="statusmsg" id="idErrorMsgEMailField">'.$errormsgEMailField.'</div>'; // Display our message and wrap it with a div with the class "statusmsg".  
                      }  
                    ?>  
                </div>
                <div id="r3">
                    <div id="r3c1">
                        <textarea name="nameField_Message" id="idField_Message" placeholder="Enter your message for us here"></textarea>
                    </div>
                    <div id="r3c2">
                <?php  
                      if(isset($errormsgMessageField)){  // Check if $msg is not empty  
                  echo '<img src="error.png" width="45" height="45" style="margin: 115px 0px" alt="">';
                      }  
                    ?> 

                    </div>
                </div>
                <div id="afterr3">
                <?php  
                      if(isset($errormsgMessageField)){  // Check if $msg is not empty  
                  echo '<div class="statusmsg" id="idErrorMsgMessageField">'.$errormsgMessageField.'</div>'; // Display our message and wrap it with a div with the class "statusmsg".  
                      }  
                    ?>  
                </div>

                <div id="r4">
                    <div id="r4c">
                        <input type="Submit" name="nameSubmit" id="idButton_Submit" value="Submit"  alt="Submit Button"/>
                    </div>
                </div>
                </form>

Any help will be great on this.

Thank You.

  • 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-06T19:06:54+00:00Added an answer on June 6, 2026 at 7:06 pm

    Try changing your tag like :

    <input type="text" 
      name="nameField_Name" 
      id="idField_Name" 
      placeholder="Enter your name here" 
      value ="<?php 
                 if (isset($phpVarNameField)) 
                  echo $phpVarNameField; 
             ?>"
    />
    .......
    <input 
       name="nameField_EMail" 
       type="text" 
       id="idField_EMail" 
       placeholder="Enter your E-Mail address here" 
       value ="<?php if (isset($phpVarEMailField)) echo $phpVarEMailField; ?>" 
     />
    .......
    <textarea name="nameField_Message" id="idField_Message" placeholder="Enter your message for us     
    here" value ="<?php if (isset($phpVarMessageField)) echo $phpVarMessageField; ?>" ></textarea>
    

    Good Luck !

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

Sidebar

Related Questions

I have an email attachment form that is working fine when the <form action=processingtheformfile.php>
I have a form, MainForm, which was working just fine and dandy until earlier
I have designed a form which was working fine until about an hour ago.
I have created a validation with two checkbox. both validations are working fine with
I have coded custom form validation. validation is working fine all browser but when
I have an HTML form, being submitted to a PHP page. The PHP page
I have created a small registration sticky form. Everything is working fine, but if
My registration page and login form is working fine. If any member register and
I'm trying to make a simple form, but it's working not so fine. This
I have a user form that is working perfectly. The page makes use of

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.