[Xerte] LoadVars

Paul Swanson Paul.Swanson at harlandfs.com
Thu Aug 30 18:24:49 BST 2007


Julian, thanks so much for the quick response!  Adding a new feature
overnight is unprecedented in my experience!
 
Yes, it is working great! It took me a little time to figure out how to
create the object holding the variables I sent from Xerte to PHP, but
once I got that going it was very easy to work with.
 
For the interest of anyone else, here is how I set up my test:
 
In Xerte, I added a page and set an id of 'varPage' for it. I then added
a script icon, with the following code to set up and send my variables
to a PHP page:
 
vars = new LoadVars ();
vars.type = 'SELECT';
vars.table = 'tableName';
vars.id = myId;
vars.sort = 'fname';
 
varPage.sendAndLoadVars('http://localhost/test/test_xerte2.php', vars);
 
My test_xerte2.php page just receives and regurgitates the variables in
a name/value pair, but I added a name/value pair that did not come from
Xerte:
 
<?php  # test_xerte2.php
foreach ($_POST as $varname => $varvalue) {
  if (empty($varvalue)) {
    $empty[$varname] = $varvalue;
  } else {
    $post[$varname] = $varvalue;
    echo "$varname=$varvalue&";
  }
}
echo "newField=newFieldValue"; // new var that didn't come from Xerte
?> 
 
Back in Xerte, I have an interaction icon, with an event response
hanging off it. In the properties of the response I have eventName set
to 'onSendAndLoadVars' and the icon property is set to 'varPage'. The
script icon added to the response had the following code:
 
type = varPage.loadVars.type;
table = varPage.loadVars.table;
eid = varPage.loadVars.id;
order = varPage.loadVars.sort;
newField = varPage.loadVars.newField;
 
replyPage.myText = '<p><b>Response from script: </b></p><br />';
 
replyPage.myText += '<br />Query Type: <i>' + type + '</i>';
replyPage.myText += '<br />Table Name: <i>' + table + '</i>';
replyPage.myText += '<br />ID: <i>' + eid + '</i>';
replyPage.myText += '<br />Order By: <i>' + order + '</i>';
replyPage.myText += '<br />New Field: <i>' + newField + '</i>';
 
Notice that all you have to do to reference a variable returned by PHP
is refer to its property in the loadVar object. Even variables created
in the PHP script can be accessed this way, but you have to know the
name of the variable created in PHP in order to get its value from the
object in Xerte. 
 
There must be a way to get a list of all properties of an object, but I
haven't found the function that does this. Is there such a function, or
snippet of code, that will return a list of all the property names? How
about a count of the number of properties, is there a function for that?
 
Thanks again, Julian!
 
- Paul
 


________________________________

	From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Tenney Julian
	Sent: Thursday, August 30, 2007 1:21 AM
	To: Xerte discussion list
	Subject: [Xerte] LoadVars
	
	
	Paul,
	 
	If you download Xerte form the website now, I have aded
IconID.loadVars(url) and IconID.sendAndLoadVars(url, loadVarsObjToSend);
	 
	The events to listen for are onLoadVars and onSendAndLoadVars.
In both cases the resulting loadVars object is IconID.loadVars.
	 
	Can you test it and let me know it works to your satisfaction?
	 
	thanks,
	 
	Julian


		 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.nottingham.ac.uk/pipermail/xerte/attachments/20070830/f5dd3a63/attachment.html


More information about the Xerte mailing list