1 Reply Latest reply on Apr 17, 2009 7:24 PM by akieru

    make browse button to load csv data into form

      Hi, I have a csv file exported form excel:


      File format is like this:


      john,smith,1905.06.07,new york


      how to make a "load csv" button on my form to load a text file that contains asingle line only like this:


      john;smith;1905.06.07;new york


      and to fill all the text field boxes on my form?


      My form code below:


      <?php require_once('Connections/my_MySQL.php'); ?>
      // Load the common classes


      // Load the tNG classes


      // Make a transaction dispatcher instance
      $tNGs = new tNG_dispatcher("");


      // Make unified connection variable
      $conn_my_MySQL = new KT_connection($my_MySQL, $database_my_MySQL);


      // Start trigger
      $formValidation = new tNG_FormValidation();
      // End trigger


      // Make an insert transaction instance
      $ins_location = new tNG_insert($conn_my_MySQL);
      // Register triggers
      $ins_location->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
      $ins_location->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
      // Add columns
      $ins_location->addColumn("firstname", "STRING_TYPE", "POST", "firstname");
      $ins_location->addColumn("lastname", "STRING_TYPE", "POST", "lastname");
      $ins_location->addColumn("birthdate", "DATE_TYPE", "POST", "birthdate");
      $ins_location->addColumn("city", "STRING_TYPE", "POST", "city");
      $ins_location->setPrimaryKey("id_location", "NUMERIC_TYPE");


      // Execute all the registered transactions


      // Get the transaction recordset
      $rslocation = $tNGs->getRecordset("location");
      $row_rslocation = mysql_fetch_assoc($rslocation);
      $totalRows_rslocation = mysql_num_rows($rslocation);
      ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>
      <link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
      <script src="includes/common/js/base.js" type="text/javascript"></script>
      <script src="includes/common/js/utility.js" type="text/javascript"></script>
      <script src="includes/skins/style.js" type="text/javascript"></script>
      <?php echo $tNGs->displayValidationRules();?>


          echo $tNGs->getErrorMsg();
      <form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
        <table cellpadding="2" cellspacing="0" class="KT_tngtable">
            <td class="KT_th"><label for="firstname">Firstname:</label></td>
            <td><input type="text" name="firstname" id="firstname" value="<?php echo KT_escapeAttribute($row_rslocation['firstname']); ?>" size="32" />
                <?php echo $tNGs->displayFieldHint("firstname");?> <?php echo $tNGs->displayFieldError("location", "firstname"); ?> </td>
            <td class="KT_th"><label for="lastname">Lastname:</label></td>
            <td><input type="text" name="lastname" id="lastname" value="<?php echo KT_escapeAttribute($row_rslocation['lastname']); ?>" size="32" />
                <?php echo $tNGs->displayFieldHint("lastname");?> <?php echo $tNGs->displayFieldError("location", "lastname"); ?> </td>
            <td class="KT_th"><label for="birthdate">Birthdate:</label></td>
            <td><input type="text" name="birthdate" id="birthdate" value="<?php echo KT_formatDate($row_rslocation['birthdate']); ?>" size="32" />
                <?php echo $tNGs->displayFieldHint("birthdate");?> <?php echo $tNGs->displayFieldError("location", "birthdate"); ?> </td>
            <td class="KT_th"><label for="city">City:</label></td>
            <td><input type="text" name="city" id="city" value="<?php echo KT_escapeAttribute($row_rslocation['city']); ?>" size="32" />
                <?php echo $tNGs->displayFieldHint("city");?> <?php echo $tNGs->displayFieldError("location", "city"); ?> </td>
          <tr class="KT_buttons">
            <td colspan="2"><label>
            <input type="submit" name="browse" id="browse" value="Load csv" />
            <input type="submit" name="KT_Insert1" id="KT_Insert1" value="Insert record" />
      <p> </p>

        • 1. Re: make browse button to load csv data into form
          Level 1

          I do use a vbs script to do the task now via browser. But your data must be structured exactly how it needs to entered and your form must move tab cursor inthe same way. So does anyone have any sugestions ?


          Here is my script, perhaps it will be handy fo somebody:


          Option Explicit
          Dim objShell, oFSO, objFile, fileLine, i
          Const strFile = "csvfile.txt"


          Set objShell = WScript.CreateObject("WScript.Shell")
          Set oFSO = CreateObject("Scripting.FileSystemObject")


          Set objFile = oFSO.OpenTextFile(strFile, 1)
          fileLine = objFile.ReadLine
          fileLine = split(fileLine, ",")


          for each i in fileLine
          objShell.SendKeys i
          objShell.SendKeys "{TAB}"




          To use it create a folder on your desktop and create new text file, then paste the code to it and save it.

          Rename the file to tabscript.vbs

          Create another text file named csvfile.txt - this file contains 1 line of csv code that must be entered into the form.

          Create a shortcut from tabscript.vbs on your desktop then right click on it and enter schortcut key ctrl+alt+T


          Now open your form and place cursor in fist text box. press the ctrl+alt+T and the script will do the work for you.