I have a form that I need to be able to post data to without having someone click a button. So I everytime the page loads I need the form data to be posted. This updates a variable on a Parallax Basic Stamp.

Can do you do this with php? With Coldfusion I think you can do this with cfhttp.

Here is my form:

<html>
<head>
</head>
<body>
<p>The value in variable 01 is: <Nb_var01></p>
<FORM method="post" action="http://192.168.0.2/test.htm">
<P>
What value would you like stored in variable 01?
<INPUT name="Nb_var01"type="text"size="24"maxlength="63">
<INPUT type="submit">
</P>
</FORM>
</body>
</html>

    Both Colfusion and PHP are server side technologies so neither one can do it.

    If CF can do it, it's because on the server side, they insert some Javascript into the HTML and the Javascript takes the action of posting something back to the server.

    So you can do the same thing with PHP... or even with HTML by itself.

    You can create a form and then include a javascript command in the body (in the onload tag) that causes the form to be submitted. The other thing you can do (which eliminates the need for a form) is to create an Ajax script that posts something to the server and again, you invoke that Ajax script command with a Javascript command in the body onload tag.

    The Ajax technique is a little cleaner because when you post a form, the browser leaves the current page and is waiting for a result page to display. With an Ajax command, the page is content to sit idle after it has reported to the server. With a timer, you can even have the Ajax script report every X seconds to continually update the Basic Stamp.

    I am unclear in your form example, however, what value is getting passed up to the server. If the HTML page has a static value to report to 192.168.0.2/test.htm, then wouldn't the Basic Stamp already know that value? If you can be a little more specific about what value the page should have and report, I can work up a little Ajax example for you.

      The value is a number such as '212421'.

      The Basic Stamp with the PINK network card adapter allows for communtication from other devices on the network via a web form (like I have) or via UDP messaging. What I was planning to do was to set up a php web server on computer on the same network as my basic stamp that would be querying a mysql database on the web (outside my local network) and then taking that data and posting it to the basic stamp via form data without the form automatically.

      The reason being is that I can not give my basic stamp an IP address that is exposed to the web. So the computer on my network is the go between of my remote mysql database and basic stamp on my local network.

        Ok. That makes more sense. In that case, no form (or Javascript or Ajax) is necessary.

        Obviously, if the BS can't contact the server outside your network (192.) then the outside server is not going to be able to communicate directly to the BS with or without a form.

        And, in fact, there is no "client side" where a form would exist.

        So you really have three entities: The BS, the computer on your network (you called it the "go between" which it is), and the remote server with the MySQL database. You have two options, both will work very well:

        The BS sends a request to the go between computer by requesting a PHP page. Either (A) that PHP page opens a MySQL connection to the remote computer with MySQL and performs a query for the data you want and PRINTS it out (no form), or (😎 that PHP page on the go between performs a second http request to a PHP page on the remote computer that performs the MySQL query locally, PRINTS the result, and the PHP script on the go between relays that information to the BS by, again, simply PRINTING the result.

        Forms are for web browsers like Internet Explorer, Firefox, or Safari. You don't need to complicate this with any client side web browsers.

        So, for clarity, here are your two options:

        1. BS -> PHP on go between -> MySQL on remote machine
          followed by PHP on go between -> BS

        or

        1. BS -> PHP on go between -> PHP on remote machine -> MySQL
          followed by PHP on remote -> PHP on go between -> BS

        All server side, no forms.

        I'm curious, though, if the go between machine can contact the remote, why can't the BS connect to the remote?

          maybe udp messaging is the best way to do this.

          So basicly I probably need to send a UDP message with php on my go between computer to the basic stamp. Does that this make better sense?

            Not sure if this is what you need, but have you looked at the [man]Curl[/man] functions?

              11 days later

              cURL should work. Have you tried something like this:

              $URL="http://192.168.0.2/test.htm";
              $ch = curl_init();

              curl_setopt($ch, CURLOPT_URL, $URL);
              curl_setopt($ch, CURLOPT_POST, 1);
              curl_setopt($ch, CURLOPT_POSTFIELDS, "Nb_var01=<Nb_var01>");
              curl_exec ($ch);

              curl_close ($ch);

                Write a Reply...