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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:16:49+00:00 2026-06-05T12:16:49+00:00

I have a form with various fiedls (Name, email, password, etc..). It also has

  • 0

I have a form with various fiedls (Name, email, password, etc..). It also has a set of 5 check-boxes. As i have to update a database i prefer doing server-side validation and i am using php.

If a validation error occurs, the error is displayed on the top of the page along with the form and the previously entered data in the text fields. I am not able to retain the state of the checkboxes and radio buttons. The all revert back to being not selected. What should i do to retain the state of checkboxes and radio buttons?

The form looks something like..:

    Password:<input type="text" name="password" size="16" maxlength="9" value="<?php echo $_POST['password']?>"/>
    Retype Password:<input type="text" name="repassword" value="<?php echo $_POST['repassword']?>"/>
    Select:<br />
    <input type="checkbox" name="option1" value="on1" id="opt1"/> <label for="opt1">Option1</label><br />
    <input type="checkbox" name="option2" value="on2" id="opt2"/> <label for="opt2">Option2</label><br />
    <input type="checkbox" name="option3" value="on3" id="opt3"/> <label for="opt3">Option3</label><br />
    <input type="checkbox" name="option4" value="on4" id="opt4"/> <label for="opt4">Option4</label><br />
    <input type="checkbox" name="option5" value="on5" id="opt5"/> <label for="opt5">Option5</label><br />
    Mobile No:<input type="text" name="mobileno" maxlength="10" value="<?php echo $_POST['mobileno']?>"/>
  • 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-05T12:16:52+00:00Added an answer on June 5, 2026 at 12:16 pm

    What you’re talking about is Sticky Forms. You can implement sticky forms in many ways, my choice is to use session. If there is an error in your validation, simply dump everything in your POST data into session. On your form page, check to see if the value is set in session and set the default value of the form control it if it is:

    Validation Page:

    <?php
        session_start();
        if(/** some error condition **/) {
            foreach($_POST as $k => $v)
                $_SESSION['sticky_'.$k] = $v;
    
            header('Location: http://site.com/yourform.php');
            exit();
        }
    ?>
    

    Form Page:

    <?php session_start(); ?>
    
    <input type = "checkbox" name = "option1" value = "on1" id = "opt1" <?php 
        if(isset($_SESSION['sticky_option1'])) 
            echo('checked = "checked"); 
    ?>/>
    
    Example TextBox: <input type = "text" name = "textBoxName" <?php 
        if(isset($_SESSION['sticky_textBoxName']))
            echo('value = "' . $_SESSION['sticky_textBoxName'] . '"');
    ?>
    
    ...
    
    <?php
        // Erase the POST values from session after the HTML is constructed.
        foreach($_SESSION as $k => $v)
            if( strpos($k, 'sticky_' !== false )
                unset($_SESSION[$k]);
    ?>
    
    • 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 has various fields to save to a database. How
I have am HTML form in a PHP page. The form has various inputs.
I have an HTML form on my website. The form has various fields and
I have an EXCEL sheet.it has various form-fields that are named as smrBgm133GallonsGross/ smrBgm167GallonsGross
I have a contact form in my flash file with name/email/message fields which a
I have a form, in which I can set various client fields like client
Say we have a form where the user types in various info. We validate
Javascript I have code that will hide various sections in a MS CRM form
My idea: I have a database of users, each user has an autoincremented id
I have a form with various fields the user need to feel out with

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.