lyndonwong
04-13-2003, 12:58 PM
Hi all, any wisdom/help on posting data from LZX input fields up to server would be greatly appreciated!
I currently have a a working PHP script (input_data.php listed below) which accepts form-post input from an HTML form (index.php listed below), and writes that data to a log form. When I try to connect to that same PHP script from an LZX front-end (SimpleFormPost.lzx listed below), the PHP script executes and writes a new log entry, but does not get the parameter data passed from the LZX front-end (sender_name, sender_email, etc.).
The attached screen grab shows the LZX front-end, the HTML front-end and the log entries generated. Notice that Lyndon's HTML post successfully relays name and email info to the first log entry, but Gropius' LZX post yields blank values for name and email in the second log entry. In case the attachment doesn't work, the screen grab is also at:
http://lyndonwong.home.att.net/SimpleFormPost/
thx in advance,
Lyndon
[source code listings]
------------------------------------------------
HTML INPUT FORM: /SimpleFormPost/index.php
------------------------------------------------
<html>
<header>
<title>Simple Form Post</title>
</header>
<BODY>
<form action="store_input.php" method="POST">
<table>
<tr><th width=40%><th width=60%></tr>
<tr>
<td>
Your name:<br>
Your email:<br>
</td>
<td>
<input type="text" name="sender_name" /><br>
<input type="text" name="sender_email" /><br>
</td>
</tr>
</table>
<br>
<small>Enter Brief Message: (max. 3 lines of text)</small>
<br>
<textarea rows=4 cols=50 name="sender_text"></textarea>
<br><br>
<input type="submit" value="Send Data">
</form>
</body>
</html>
------------------------------------------------
LZX INPUT FORM: SimpleFormPost.lzx
------------------------------------------------
<canvas width="900" height="700" debug="true" >
<include href="redmond" />
<!-- DATASET DECLARATIONS -->
<dataset name="dsSendData" autorequest="false" src="http://192.168.1.4/~lyndonwong/SimpleFormPost/store_input.php" type="http" >
<method event="ondata">
debug.write(this.getPointer().getXPath("result/text()"));
</method>
</dataset>
<!-- APPLICATION INTERFACE -->
<view name="formFields">
<text y="10"> Name: </text>
<windowtext name="sender_name" datapath="@sender_name" width="100" x="80" y="10" />
<text y="35"> Email: </text>
<windowtext name="sender_email" datapath="@sender_email" width="100" x="80" y="35" />
<text y="60"> Message: </text>
<windowtext name="sender_text" datapath="@sender_text" width="100" x="80" y="60" />
<method name="sendData" >
var d=canvas.datasets.dsSendData;
var p=new LzParam();
p.addValue("sender_name", sender_name.getText(), true);
p.addValue("sender_email", sender_email.getText(), true);
p.addValue("sender_text", sender_text.getText(), true);
d.setQueryString(p);
debug.write(p);
d.doRequest();
</method>
</view>
<view y="90" >
<simplelayout axis="x" />
<button width="100" > Send Data
<method event="onclick">
canvas.formFields.sendData();
</method>
</button>
</view>
</canvas>
------------------------------------------------
SERVER-SIDE PHP SCRIPT: store_input.php
------------------------------------------------
<?php
/***************************************
** Filename.......: store_input.php
** Project........: SimpleFormPost
** Last Modified..: 13 April 2003
***************************************/
/***************************************
** The header() makes
** the output look lovely.
***************************************/
header('Content-Type: text/plain');
/******************************
** Prepare log entry data
******************************/
/***************************************
** These parameters passed from the
** calling script.
***************************************/
$msg_sender_name = $_POST["sender_name"];
$msg_sender_email = $_POST["sender_email"];
$msg_sender_text = $_POST["sender_text"];
/***************************************
** These parameters generated dynamically
** using PHP function calls.
***************************************/
$msg_date = date("Y-m-d");
$msg_time = date("H:i:s");
$msg_sender_ip = $_SERVER["REMOTE_ADDR"];
$msg_sender_hostname = gethostbyaddr($msg_sender_ip);
$msg_sender_browser = $_SERVER["HTTP_USER_AGENT"];
/************************************************** ****
** Write data to log file
************************************************** *****/
$filename = 'SimpleFormPost.log'; // Edit this path to access desired log file.
$log_entry = "<date>" . $msg_date . "</date>" . "<time>" . $msg_time . "</time>" . "<IP>" . $msg_sender_ip . "</IP>" . "<host>" . $msg_sender_hostname . "</host>" . "<name>" . $msg_sender_name . "</name>" . "<email>" . $msg_sender_email . "</email>" . "<browser>" . $msg_sender_browser . "</browser>" . "<destination>" . $msg_destination . "</destination>" . " \n";
// Make sure the file exists and is writable first.
if (is_writable($filename)) {
// opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $log_entry will go when we fwrite() it.
if (!$fp = fopen($filename, 'a')) {
print "Cannot open file ($filename)";
exit;
}
// Write $log_entry to our opened file.
if (!fwrite($fp, $log_entry)) {
print "Cannot write to file ($filename)";
exit;
}
// print "Success, wrote ($log_entry) to file ($filename)";
fclose($fp);
} else {
print "The file $filename is not writable";
}
// CONFIRMATION MESSAGE IN XML FORMAT.
echo "<result>"."\n";
echo "<name>".$msg_sender_name."</name>"." \n";
echo "<email>".$msg_sender_email."</email>"." \n";
echo "<msg_text>".$msg_sender_text."</msg_text>"." \n";
echo "<msg_status>".$msg_status."</msg_status>"." \n";
echo "</result>"."\n";
?>
I currently have a a working PHP script (input_data.php listed below) which accepts form-post input from an HTML form (index.php listed below), and writes that data to a log form. When I try to connect to that same PHP script from an LZX front-end (SimpleFormPost.lzx listed below), the PHP script executes and writes a new log entry, but does not get the parameter data passed from the LZX front-end (sender_name, sender_email, etc.).
The attached screen grab shows the LZX front-end, the HTML front-end and the log entries generated. Notice that Lyndon's HTML post successfully relays name and email info to the first log entry, but Gropius' LZX post yields blank values for name and email in the second log entry. In case the attachment doesn't work, the screen grab is also at:
http://lyndonwong.home.att.net/SimpleFormPost/
thx in advance,
Lyndon
[source code listings]
------------------------------------------------
HTML INPUT FORM: /SimpleFormPost/index.php
------------------------------------------------
<html>
<header>
<title>Simple Form Post</title>
</header>
<BODY>
<form action="store_input.php" method="POST">
<table>
<tr><th width=40%><th width=60%></tr>
<tr>
<td>
Your name:<br>
Your email:<br>
</td>
<td>
<input type="text" name="sender_name" /><br>
<input type="text" name="sender_email" /><br>
</td>
</tr>
</table>
<br>
<small>Enter Brief Message: (max. 3 lines of text)</small>
<br>
<textarea rows=4 cols=50 name="sender_text"></textarea>
<br><br>
<input type="submit" value="Send Data">
</form>
</body>
</html>
------------------------------------------------
LZX INPUT FORM: SimpleFormPost.lzx
------------------------------------------------
<canvas width="900" height="700" debug="true" >
<include href="redmond" />
<!-- DATASET DECLARATIONS -->
<dataset name="dsSendData" autorequest="false" src="http://192.168.1.4/~lyndonwong/SimpleFormPost/store_input.php" type="http" >
<method event="ondata">
debug.write(this.getPointer().getXPath("result/text()"));
</method>
</dataset>
<!-- APPLICATION INTERFACE -->
<view name="formFields">
<text y="10"> Name: </text>
<windowtext name="sender_name" datapath="@sender_name" width="100" x="80" y="10" />
<text y="35"> Email: </text>
<windowtext name="sender_email" datapath="@sender_email" width="100" x="80" y="35" />
<text y="60"> Message: </text>
<windowtext name="sender_text" datapath="@sender_text" width="100" x="80" y="60" />
<method name="sendData" >
var d=canvas.datasets.dsSendData;
var p=new LzParam();
p.addValue("sender_name", sender_name.getText(), true);
p.addValue("sender_email", sender_email.getText(), true);
p.addValue("sender_text", sender_text.getText(), true);
d.setQueryString(p);
debug.write(p);
d.doRequest();
</method>
</view>
<view y="90" >
<simplelayout axis="x" />
<button width="100" > Send Data
<method event="onclick">
canvas.formFields.sendData();
</method>
</button>
</view>
</canvas>
------------------------------------------------
SERVER-SIDE PHP SCRIPT: store_input.php
------------------------------------------------
<?php
/***************************************
** Filename.......: store_input.php
** Project........: SimpleFormPost
** Last Modified..: 13 April 2003
***************************************/
/***************************************
** The header() makes
** the output look lovely.
***************************************/
header('Content-Type: text/plain');
/******************************
** Prepare log entry data
******************************/
/***************************************
** These parameters passed from the
** calling script.
***************************************/
$msg_sender_name = $_POST["sender_name"];
$msg_sender_email = $_POST["sender_email"];
$msg_sender_text = $_POST["sender_text"];
/***************************************
** These parameters generated dynamically
** using PHP function calls.
***************************************/
$msg_date = date("Y-m-d");
$msg_time = date("H:i:s");
$msg_sender_ip = $_SERVER["REMOTE_ADDR"];
$msg_sender_hostname = gethostbyaddr($msg_sender_ip);
$msg_sender_browser = $_SERVER["HTTP_USER_AGENT"];
/************************************************** ****
** Write data to log file
************************************************** *****/
$filename = 'SimpleFormPost.log'; // Edit this path to access desired log file.
$log_entry = "<date>" . $msg_date . "</date>" . "<time>" . $msg_time . "</time>" . "<IP>" . $msg_sender_ip . "</IP>" . "<host>" . $msg_sender_hostname . "</host>" . "<name>" . $msg_sender_name . "</name>" . "<email>" . $msg_sender_email . "</email>" . "<browser>" . $msg_sender_browser . "</browser>" . "<destination>" . $msg_destination . "</destination>" . " \n";
// Make sure the file exists and is writable first.
if (is_writable($filename)) {
// opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $log_entry will go when we fwrite() it.
if (!$fp = fopen($filename, 'a')) {
print "Cannot open file ($filename)";
exit;
}
// Write $log_entry to our opened file.
if (!fwrite($fp, $log_entry)) {
print "Cannot write to file ($filename)";
exit;
}
// print "Success, wrote ($log_entry) to file ($filename)";
fclose($fp);
} else {
print "The file $filename is not writable";
}
// CONFIRMATION MESSAGE IN XML FORMAT.
echo "<result>"."\n";
echo "<name>".$msg_sender_name."</name>"." \n";
echo "<email>".$msg_sender_email."</email>"." \n";
echo "<msg_text>".$msg_sender_text."</msg_text>"." \n";
echo "<msg_status>".$msg_status."</msg_status>"." \n";
echo "</result>"."\n";
?>