Saving the values of form elements after an incomplete submission

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fernando Rodríguez

    Saving the values of form elements after an incomplete submission


    Hi,

    I'm writing a form that requires validation. After submission, the form fields
    (mostly textboxes) are validated and if any is incorrect, the form is redisplayed
    with all the value sin place so the user doesn't have to retype everything.

    I'm achieving the latter this way:

    <input type="text" name="whatever" value="<?php echo $_POST['whatever']
    ?>" >

    This is fine with text boxes, but how can I do this with listboxes and option
    buttons?

    Thanks


  • qummik

    #2
    Re: Saving the values of form elements after an incomplete submission

    for list:
    <select name="list">
    <option value="value1"< ?php if($_POST["list"]=="value1") { echo"
    selected"; } ?>>item1</option>
    <option value="value2"< ?php if($_POST["list"]=="value2") { echo"
    selected"; } ?>>item2</option>
    </select>

    for radio buttons:
    <label><input name="radio" type="radio" value="radio1"< ?php
    if($_POST["radio"]=="radio1") { echo" checked"; } ?>>radio1</label>
    <label><input name="radio" type="radio" value="radio2"< ?php
    if($_POST["radio"]=="radio2") { echo" checked"; } ?>>radio2</label>


    Comment

    Working...