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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:37:22+00:00 2026-06-03T00:37:22+00:00

In my register form, if a validation message needs to appear when the user

  • 0

In my register form, if a validation message needs to appear when the user clicks submit, the whole text out of all the boxes disappears, meaning they have to start again!

What PHP code do I need to add so the data remains?

        Username<span class="required">*</span> 
        <input name="user_name" type="text" id="user_name" minlength="5" >

        Full Name<span class="required">*</span> 
        <input name="full_name" type="text" id="full_name" size="30" 

       Nationality <span class="required">*</span>
        <select name="nationality"  id="select8">
            <option value="" selected></option>
            <option value="Afghanistan">Afghanistan</option>
            <option value="Albania">Albania</option>
        </select>

 <p align="center">
      <input name="doRegister" type="submit" id="doRegister" value="Register">
      </p>
  EDIT:   

I have tried this:

        <?php
        $email_field = ($_POST['usr_email']);
        ?>
        Email<span class="required">*</span>
        <input type="text" id="usr_email3" name="usr_email" value="<?php echo   
        $email_field; ?>" />

but it says usr_email is not defined

  • 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-03T00:37:24+00:00Added an answer on June 3, 2026 at 12:37 am

    As described in the HTTP specs, HTTP is stateless. That means that eventhough the user got to the page through a previous page the server has no idea of this. Each request is completely new, so it cant just send the previous output back.

    You’ll have to read the values send to your form out of $_POST, and resend that. For example:

    <?php
        //If the POST parameter has been send, set it to the $username variable. Otherwise make it empty.
        $username = array_key_exists('username', $_POST) ? $_POST['username'] : '';
    ?>
    
    <form name='f1' method='POST'>
    
    <!-- Show username as its value, thus preserving state. -->
    Name: <input type='text' value='<?php echo $username ?>' name='username' />
    <input type='submit' value='Go' />
    
    </form>
    

    For select inputs (usually dropdown) you need to set the selected attribute on the correct option. As such:

    <?php
        $gender = array_key_exists('gender', $_POST) ? $_POST['gender'] : 'unknown'; //Default to unknown
    ?>
    
    <form name='f1' method='POST'>
    
    <select name='gender'>
    
        <!-- The $gender will be the value of each option. -->
        <option <? if($gender == 'unknown') { ?> selected <? } ?> value='unknown'>Unknown</option>
        <option <? if($gender == 'male') { ?> selected <? } ?> value='male'>Male</option>
        <option <? if($gender == 'female') { ?> selected <? } ?> value='female'>Female</option>
    
    </select>
    
    
    <input type='submit' value='Go' />
    
    </form>
    

    However i still recommend you buy a proper book, or read more tutorials. After you feel more comfortable as a developer you can explore and find these solutions youself, as we all here did once.

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

Sidebar

Related Questions

I am creating a form where a user will register with a struts2 application.
In my web application i have registration form, when user register i want to
someone has used this jquery plugin for form validation? http://docs.jquery.com/Plugins/Validation i cant figure out
my form validation does not firing...if i try to submit this form without entering
I have the following code, which works nicely: $('#register form .submit input').click(function(){ if(jQuery.trim($('#new-usr').val()) ==
In Register.php, it contains a form. <html> <body> <form action=Insert.php method=post> Email: <input type=text
Nowadays we see websites with login form/register form in the home page itself (to
I succeeded to create a register form, and now users can register my site.
I have two links with classes (login-form and register-form) relevant to their target forms
def register_page(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): user = User.objects.creat_user(

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.