Results 1 to 1 of 1

Thread: Fill HTML Form from Text File

  1. #1
    Join Date
    Aug 2009
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Fill HTML Form from Text File

    Hi All,

    This is kind of hard for me to explain so bear with me:

    I'm working on a "Job Request Form". I have a plain HTML form, and when submitted, its contents are passed to a confirmation page, which contains the following script: (this script creates and fills a new text file)

    Code:
    <?php
    // Set some variables
    $filename = 'data/' . $_POST['projName'] . '.txt';
    $newevent = $_POST['projName'] . ' | ' . $_POST['stockNum'] . ' | ' . $_POST['dueDate'] . ' | ' ... ;
    	
    // Create text file and write job data to file
    $handle = fopen($filename, 'w');
    $text = $newevent;
    fwrite($handle, $text);
    fclose($handle);
    header('Refresh: 3; url=index.php');
    ?>
    As you can probably see from the last line in the preceding script, there is a redirect to the index.php page, which contains the following script: (this script creates and displays a link for each job that has been created)

    Code:
    <?php
    if ($handle = opendir('data/')) {
       while (false !== ($file = readdir($handle))) {
          if ($file != "." && $file != "..") {
             echo '<p><a href="job_web_filled.php">' . $file . '</a></p>';
          }
        }
        closedir($handle);
    }
    ?>
    All of the form fields in the "job_web_filled.php" form contain variables which allow the form to be filled from the text files. The very top bit of script on this form looks like this:

    Code:
    <?php
    $dir = "data/";
    	
    if ($dh = opendir($dir)) {
       while (($file = readdir($dh)) !== false) {
          $data = file_get_contents('data/' . $file);
          list($projName, $stockNum, $dueDate, $jobSheetStarted, $toEditing, $toDesign, $layoutStarted, $contactPerson, $layoutBy, $contactPhone, ... $addtlNotes) = explode(" | ", $data);
       }
       closedir($dh);
    }
    ?>
    The problem I'm having is that the form is only being filled by the last job in the list. So, each time you click on a link, doesn't matter which one, the information that fills the form belongs to the last job/text file in the list.

    I can't figure out how to fix this and would really appreciate any help at all.

    Thanks in advance!

    - Jenn
    Last edited by pelaej; 08-11-2010 at 01:20 PM.

Bookmarks

Posting Permissions

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