PHP Sticky checkboxes

Posted on 2006-03-29
Last Modified: 2013-12-12
I have a form with a series of checkboxes. If the user does not complete other information on the form, user submits, the form is redisplayed and I want the completed fields to be sticky. (I think that is the right term fields already completed to redisplay) including the checkboxes.

<input type="checkbox" name='otherMarketing[]' value="membership" id="membership"  <?php if ($_REQUEST[otherMarketing][membership]=='membership') { echo "checked";} ?> />
Question by:MarleneAyers
    LVL 33

    Expert Comment

    You'd have to name the checkbox 'otherMarketing[membership]' for that to work as written.
    LVL 49

    Accepted Solution

    Or use:

    <?php if(in_array('membership',$_REQUEST['otherMarketing'])) { echo 'checked="checked"';} ?>


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now