Handling POST forms and data
Posted: 31 Jul 2017 17:48
I had this working at one time and something is now broken. I've modified the SecurityMode module in Zway to send data via "POST" to an Apache2 webserver running on my ZWay box (Raspbian Jessie and Zway v2.1.1) when a motion detector turns on. The modified section of the SecurityMode module is :
// If Email exist, then send email
if (self.email)
{
http.request(
{
method: 'POST',
url: "http://192.168.1.99",
data:
{
to: self.email,
subject: "Notification from Smart Home",
message: self.message
}
});
}
The PHP code at the root location of the Apache2 webserver is:
<?php
//if "to" variable is filled out, send email
if (isset($_POST["to"]))
{
//send email
mail($_POST["to"], $_POST["subject"], $_POST["message"]);
}
else
{
//Write error file
$fil = fopen('/tmp/zway-email-error.txt', w);
fwrite($fil, "Error in SecurityMode App Form");
fclose($fil);
}
?>
The above php code works if I create an index.html file/page to prompt me to fill out a form then call an "action" to execute the php file. If I want Zway to make an http request (I'm assuming it's using Mongoose) in the SecurityMode module, how do I tell the Apache2 website to accept the posted form data? I had this figured out at one time but now I'm confused. Any help will be appreciated!
// If Email exist, then send email
if (self.email)
{
http.request(
{
method: 'POST',
url: "http://192.168.1.99",
data:
{
to: self.email,
subject: "Notification from Smart Home",
message: self.message
}
});
}
The PHP code at the root location of the Apache2 webserver is:
<?php
//if "to" variable is filled out, send email
if (isset($_POST["to"]))
{
//send email
mail($_POST["to"], $_POST["subject"], $_POST["message"]);
}
else
{
//Write error file
$fil = fopen('/tmp/zway-email-error.txt', w);
fwrite($fil, "Error in SecurityMode App Form");
fclose($fil);
}
?>
The above php code works if I create an index.html file/page to prompt me to fill out a form then call an "action" to execute the php file. If I want Zway to make an http request (I'm assuming it's using Mongoose) in the SecurityMode module, how do I tell the Apache2 website to accept the posted form data? I had this figured out at one time but now I'm confused. Any help will be appreciated!