Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Preserving form data on reload

    I have a form with input, radio, select and checkboxes and am trying to get the data to stay populated I have the input box working with this to preserve the data

    PHP Code:
    <input tabindex="4" type="text" name="city" id="city" value="<? echo ( isset( $_POST['city'] ) && $_POST['city'] ) ? $_POST['city']:""?>" size="30" maxlength="30" />
    but does anyone know how to preserve what the user entered for select dropdowns, radio buttons and checkboxes? My checks disappear and my dropdowns revert back to "Choose one"

  • #2
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Is it like a reference page where the user can choose preference via Check box & Radio buttons & then view the page later & you want the options he chose to be chosen?

    This might help...
    Menu Options - Selected

  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    that looks like it. will this work for both radio and checkboxes?

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    $myChk 
    'yes';
    $mySel 'Blue';
    ?>
    <form name="form1" method="post" action="">
      <p>
        <input <?php if (!(strcmp($myChk,"yes"))) {echo "checked";} ?> type="checkbox" name="checkbox" value="yes">
    </p>
      <p>
        <select name="select">
          <option value="Red" <?php if (!(strcmp("Red"$mySel))) {echo "SELECTED";} ?>>Red</option>
          <option value="Green" <?php if (!(strcmp("Green"$mySel))) {echo "SELECTED";} ?>>Green</option>
          <option value="Blue" <?php if (!(strcmp("Blue"$mySel))) {echo "SELECTED";} ?>>Blue</option>
        </select>
    </p>
    </form>

  • #5
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by degsy
    PHP Code:
    <?php
    $myChk 
    'yes';
    $mySel 'Blue';
    ?>
    <form name="form1" method="post" action="">
      <p>
        <input <?php if (!(strcmp($myChk,"yes"))) {echo "checked";} ?> type="checkbox" name="checkbox" value="yes">
    </p>
      <p>
        <select name="select">
          <option value="Red" <?php if (!(strcmp("Red"$mySel))) {echo "SELECTED";} ?>>Red</option>
          <option value="Green" <?php if (!(strcmp("Green"$mySel))) {echo "SELECTED";} ?>>Green</option>
          <option value="Blue" <?php if (!(strcmp("Blue"$mySel))) {echo "SELECTED";} ?>>Blue</option>
        </select>
    </p>
    </form>
    If you are quering from a DB then you just set it like this?
    PHP Code:
                $search mysql_query("SELECT * FROM table WHERE customers_id= '$id' ");
                while (
    $line mysql_fetch_array($search)) {
                
    $myChk $line["column_name"];
                
    $mySel $line["column_name"];
                } 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •