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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:45:30+00:00 2026-06-16T00:45:30+00:00

heartily regards from me I need to retain values in text boxes after submit

  • 0

heartily regards from me
I need to retain values in text boxes after submit button on click if found error.
basically the thing I want, if user left any fields blank and press save button then error message pop up and without refreshing the page it takes back the user to the form where he just have to fill the fields that were left blank… below is my code

<html>
<form method="post" action="">
Enter Name  :   <input type="text" name="name" /><br/>
Enter Password  :   <input type="password" name="pass" /><br/>
<input type="submit" name="save" value="Save" />
</form>
</html>
php code
<?php
if (isset($_POST["save"]))
{
$name = $_POST["name"];
$pass = $_POST["pass"];
if (($name == '') && ($pass == '')) 
{
echo "Fields Must Be Filled...";
exit();
}
if ($name == '') {
echo "Enter Name...";
exit();
}
if ($pass == '') {
echo "Enter Password...";
exit();
}
else
{        
echo "Your name " . $name;
echo "<br/>";
echo "Your Password " . $pass;
}
}
?>
  • 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-16T00:45:31+00:00Added an answer on June 16, 2026 at 12:45 am

    First, a little easier approach for your POST handling. You can do a

    foreach( $_POST as $key => $value )
    {
       ${$key} = $value;
       //If you need to database process the data, you can put mysql_escape_string( $value );
    }
    

    Now, all your POSTs will be in variables with the name of the field.

    After processing them for errors and more, and you wish them to be in your form element’s value. You can just use the variable

    <input type="text" name="email" value="<?=$email?>">
    

    Or, if you use the POST

    <input type="text" name="email" value="<?=$_POST['email']?>">
    

    Best regards.
    Jonas

    Working code 🙂

    <?php
    if (isset($_POST["save"]))
    {
        //Run through all objects set in the POST array
        foreach( $_POST as $key => $value )
        {
            //Set a variable named the same as the input elements name, and with the value
            ${$key} = $value;
        }
    }
    
        $error = false;
        if( empty($name) && empty($pass) ) 
        { 
            $error = true;
            $message = "Fields must be filled...";
        }
        elseif( empty($name) )
        { 
            $error = true;
            $message = "Enter name...";
        }
        elseif( empty($pass) )
        {
            $error = true;
            $message = "Enter Password...";
        }
    
        if( $error == true && isset($message) )
        {
            echo $message."<br><br>";
        }
        else
        {
            echo "Your name " . $name;
            echo "<br/>";
            echo "Your Password " . $pass;
        }
    ?>
    <html><br><br>
    <form method="post" action="">
    Enter Name  :   <input type="text" name="name" value="<?=(isset($name) ? $name : "")?>"/><br/>
    Enter Password  :   <input type="password" name="pass" value="<?=(isset($pass) ? $pass : "")?>" /><br/>
    <input type="submit" name="save" value="Save" />
    </form>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add a real-time element to my web application. Basically, I need
I'm doing a project about migrating a legacy GUI program from Motif to Gtk.
I wanted to chop off all but the first five elements of an array,
I am using Core-plot to plot vertical bar chart. In that is it possible
I've pretty much tried every Python web framework that exists, and it took me
I have a custom NSObject class(Downloader) which uses NSOperationQueue to download images and as
In this (rather old) article, the author states: Port Blocking Port blocking allows an
i have a div with fallowing css style.. background-color: #FFFFFF; border: 1px solid #C3CFD1;
I am trying to compare stl map and stl unordered_map for certain operations. I
I am having hard time trying to generate PDF files containing Greek letters using

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.