Redisplaying form data with original form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Denver Dave
    Member
    • Sep 2004
    • 49

    Redisplaying form data with original form

    Let say that we have a variety of fancy html forms that accept input and capture the data either by sending an email or saving in a database. The client really likes the form layouts and would like to review the data by displaying the saved data at a later date using the original form layout.

    Let's say that at a later date we have managed to pass the results back to the form and have them available as memory variables.

    It there a php routine that would identify the all the form elements, names and values such as <input type ="radio" name="radio1" value="1"> and insert php code such as <?php if (isset(radio1) and $radio1 == '1') echo '&nbsp;checked'; ?> inside of each input tag in the entire form.

    Then we could use modified versions of different html forms to redisplay the data - that's the idea anyway. Any idea where to start or if anyone has already done this?

    Thanks
    Dave
  • Jonathan
    Senior Member
    • Mar 2004
    • 1229

    #2
    Pretty much just pull the info from MySQL, then echo the values
    for the attribute "value" in the forms. As for checkboxes,
    select fields and radio buttons- I guess just add value="1" ?
    Not sure there.

    If you've ever made a edit form for a site before--
    its the same thing I'd reckon.
    "How can someone be so distracted yet so focused?"
    - C

    Comment

    • sdjl
      Senior Member
      • Mar 2004
      • 502

      #3
      I'm just going to elaborate on what Jonathan said.
      If you store the data in MySQL, you would then use the extracted data, like so:
      PHP Code:
      $sql "SELECT data, stuff, FROM table WHERE formid='xyz'";
      $query mysql_query($sql) or die(mysql_error());

      $row mysql_fetch_assoc($query);

      echo 
      '<input type="text" name="input_name" value="'.$row['data'].'" />'
      When it comes to check box and radio buttons, you could use a simple ternary comparison to see if the radio button needs to be checked:
      PHP Code:
      echo '<input type="radio" name="radio1" value="1" '.($row['radio1'] == 1) ? 'checked'''.'/>'
      Hope that helps

      David
      -----
      Do you fear the obsolescence of the metanarrative apparatus of legitimation?

      Comment

      • Denver Dave
        Member
        • Sep 2004
        • 49

        #4
        The client has a large form with 100 or more questions, some of which have radio buttons for 5 possible answers. So far I've resisted the urge to jump in and manually code the php. Would it be possible to write a php script to read a regular html form, identify the form elements, compare the name of each form element to memory variables and insert the appropriate php in the form element.

        Seems like a lot of work, but there is a big payback. With the above any html form that submits data could be run through the routine and used to display the results.

        I'm about to give up and write the form with php in the first place, but it would be nice to be able to handle any html form.

        Thanks.
        Dave

        Comment

        • sdjl
          Senior Member
          • Mar 2004
          • 502

          #5
          In theory you could write something to do that.
          You'd have to read the HTML form into PHP and then split it apart as per your needs. You'd then need to loop through all of the HTML looking for a certain "phrase", "name" or unique identifier and do something based on that.

          David
          -----
          Do you fear the obsolescence of the metanarrative apparatus of legitimation?

          Comment

          Working...