Board Logo

Passing variables from Tables to external programs
spw - 6/24/2007 at 08:23 AM

Some experiences using Tigra Tables Pro
----------------------------------------

Initial use of Tirgra Tables Pro was the "traditional" aspect of allowing viewers choose to see any one of a range of "objects" (articles, pictures, etc). To do this the hidden index column has the name of the object explicitly coded.

Examples of and extract from articles_content.js is as follows:

["art_012", "George", "Martin", "Moorabbin Standard", '12-11-1996'],
["art_013", "George", "Martin", "Moorabbin Standard", '19-04-1996'],
["art_032", "May", "Pang", "Sandringham-Brighton Advertiser", '22-06-1998'],
["art_020", "John", "Phillips", "Moorabbin Standard", '16-09-1997'],
["art_030", "Francis", "Rossi", "Sandringham-Brighton Advertiser", '07-03-1998'],
["art_008", "Ringo", "Starr", "Moorabbin Standard", '13-07-2005']

The above shows that the hidden column holds the actual name of the article to be retrieved minus the extension
(html,jpg etc). In this case, while each object is different in format and content, they are all html files, so the articles_template.js contains the following:

function row_clck(marked_all, marked_one) {
window.location = "./articles/"+marked_one+".htm";
}

The above sets the current window by concatenating the three parts of the created URL.
In the above exmple if the third row was chosen the URL would be set to "./articles/art_032.htm".


Getting a bit more sophisticated
--------------------------------

Two variations of the above - one where the main web page comprises a header frame and a body frame and the chosen
content is to be displayed in the body frame, and another variation where I want the chosen display in its own
independent window.

1) The initial site declaration (index.htm) is as follows:

<html>
<frameset rows="110,*" frameborder="No" border="0" framespacing="0" cols="*">
<frame name="topFrame" scrolling="No" noresize src="topfrm-ie.htm" >
<frame name="mainFrame" src="main.htm">
</frameset>

The above shows that the header frame and body frames are namd "topFrame" and "mainFrame" respectively.
A word of warning to the uninitiated: reference to frame names is case sensitive!!!

Now when a viewer chooses a row in the table which is displayed in the mainFrame, I need to make sure the chosen
content replaces the displayed table in the same frame. The articles_tamplate.js file is now modified as follows:

// onclick funtion for spawing data views - gets src from key value in col 0
function row_clck(marked_all, marked_one) {
top.frames.["mainFrame"].location.href = "./articles/"+marked_one+".htm";
}

The above shows that the browser is explicitly being directed to use the frame called "mainFrame".


2) Displaying the cosen content in its own window is slightly simpler. The articles_tamplate.js file contains the following:

// onclick funtion for spawing data views - gets src from key value in col 0
function row_clck(marked_all, marked_one) {
window.open("./articles/"+marked_one+".htm",'mywindow');
}

This forces the browser to spawn a new window for the chosen content.


Passing variables to a referenced program
-----------------------------------------
The final challenge came when designing a site for and Alumni association - tables used to list all the members and
the key here was that each alumnus profile would be displayed in an identical way - so why not just have one program do the display and just pass it the information required for the chosen profile.

Essentailly the process would be: CHOOSE ROW -> ACTIVATE DISPLAY ROUTINE AND PASS IT PROFILE NAME

As this activity has to occur on the server side it requires PHP. So far so good - Use PHP on a server which allows
variable passing eg: invoke disp_profile.php?profilename="jack'.
This is a no-brainer - the hidden column only needs
to contain the profile key and the template file could have something like the following:

// onclick funtion for spawing data views - gets src from key value in col 0
function row_clck(marked_all, marked_one) {
top.frames["mainFrame"].location.href = "./disp_profile.php?profilename="+marked_one);
}

However, passing variables in this way is inherently insecure and exposes the system to attack - most ISP's now disallow this method.

The other method to passs information between PHP programs is using forms and the POST method so here are the basic elements of what I did:


In the code that displays the table of names I defined a form which included a hidden field called "profilename".

<script language="JavaScript">
new TTable(TABLE_CAPT, TABLE_CONTENT, TABLE_LOOK);
</script>

<form name='profileform' method='post' action='./buildprofile.php'>
<input type='hidden' name='profilename'>
</form>

Note that the form "action" also nominates the program to which the profile name will be passed and which will build
the display. The profile_template file is included in the same code that displays the table so it merely needs to
set the form field to the marked_one value and send the form off....

// onclick funtion for spawing data views - gets src from key value in col 0
function row_clck(marked_all, marked_one) {
document.profileform.profilename.value=marked_one;
document.profileform.submit();
}

And that is almost all there is to it - disp_profile.php extracts the variable thus:
$profilename = $HTTP_POST_VARS['profilename'];
and can use this to access the appropriate database file etc.

Its so great when stuff like this works - it's magic......


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/