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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:08:58+00:00 2026-05-31T20:08:58+00:00

I have a form whose action is set to itself. I want it this

  • 0

I have a form whose action is set to itself. I want it this way so that is returns previously entered values if you have already submitted the form once (with an error), so that you don’t have to completely redo the form. I have:

<?php

if (isset($_POST['submit'])) {
$firstname= $_POST['firstname'];
$lastname= $_POST['lastname'];
$output_form= false;

if ($firstname== "empty($firstname) && empty($lastname)) {
echo "you forgot you first and last names!!";
$output_form= true;
}

if (!empty($firstname) && empty($lastname)) {
echo "you forgot your last name.";
$output_form= true;
}

if (empty($firstname) && !empty($lastname)) {
echo "you forgot your firstname.";
$output_form= true;
}

if (!empty($firstname) && !empty($lastname)) {
echo "good job!!";
}

}

else 
{
$output_form= true;
}

if ($output_form) { 
?>

<form method="post" action=" <?php echo $_SERVER['PHP_SELF']; ?>">
First Name: <input type="text" name="firstname" value="<?php echo $firstname ?>"/>
Last Name: <input type="text" name="lastname" value="<?php echo $lastname ?>"/>
<input type="submit" name="submit" value="submit"/>
</form>

<?php 
}
?>

If the form has not yet been submitted the $output_form variable will return true in my if statement. But I get an error because the variables $firstname and $lastname are not yet defined (because the isset($_POST['submit'] returns a false value; the form has not yet been submitted) What can I do to keep my form “sticky”?

  • 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-31T20:08:59+00:00Added an answer on May 31, 2026 at 8:08 pm

    set default values for your variables

    $firstname = '';
    $lastname  = '';
    
    if(isset($_POST['submit'])) {
        $firstname = $_POST['firstname'];
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that contains dataGridView, whose coloumn are set to dgrv1.Width =dgrv1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)+20;
I have an HTML form whose action should be set dynamically through JavaScript. How
In abc.php, i have a form whose action is xyz.php. I want $email=$POST['txtEmail'] to
I have form that displays several keywords (standard set of choice lists that changes
i have form action file in another directory but some file send to this
no title that fits this bug but this how it goes, i have form
Say I have a form whose action target expects a value with spaces in
Let's say I have a form where users can search for people whose name
I have form with few buttons and I want to know what button is
When I have a Model or ViewModel with values that are sent from the

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.