Back to ESAcademy Home Page


www.cmx.comInternet connectivity: The time is right and the technology is ready for you

By Olaf Pfeiffer and John Rodrigues

[ Introduction | Internet Connectivity Parameters | Case Study ]
[ Adapting the Software | Dynamic Web Pages | Feedback with Forms ]
[ Continuous Refresh | Security | Summary ]

 

Home

News

Training Classes

Products

Consulting

Technical Library

Contact Us

Recommended Books

< Previous Page

Feedback With Forms

So far, we had the option of getting data from the application transmitted to the browser of the user - what we still needed was a way to get commands from the user back to the application.

This functionality can be implemented using standard HTML forms. Much as with the SSI functions, the Web page needs to contain the tags to build a FORM and indicate the name of the POST function to be executed within the Web server.

Let's assume we have a form with a text field for user input and maybe a pull-down menu with a few items. Once the user hits the "Send" or "Submit" button, a POST request is sent to the HTTP server with all variable settings squeezed into a single ASCII line. The format of this line is the same as used when passing variables in URLs:

variable1=value1&variable2=value2&variable3=value3...

In case spaces are used in string variables, they have to be replaced by "%20".

Once the HTTP server receives such a POST message, it locates the application function matching the post request and executes it. The TCP/IP software eases the search for a specific variable in this ASCII line by providing search functions that allow the application function for that FORM to easily detect the variables and their current settings and respond accordingly.

Our example in listing 2 shows a function that is called by the HTTP server when a certain POST request is detected. In this case the variables named "d1" and "d2" are detected and used to switch on/off 2 LEDs.

// passed is a pointer to the socket being used for
// the web server end of the connection that just
// received a POST command

void mypostfunction(PSOCKET_INFO socket_ptr)
{
  // buffer to receive values of posted variables
  byte buf[2];

  // turn d1 on or off depending on whether a variable
  // called d1 was posted or not

  if (mn_http_find_value(BODYptr, (byte *)"d1", buf))
    *LEDs = *LEDs | 0x10; // led d1 on
  else
    *LEDs = *LEDs & 0xEF; // led d1 off

  // turn d2 on or off depending on whether a variable
  // called d2 was posted or not

  if (mn_http_find_value(BODYptr, (byte *)"d2", buf))
    *LEDs = *LEDs | 0x20; // led d2 on
  else
    *LEDs = *LEDs & 0xDF; // led d2 off

  // return HTTP code 204 which means "no content" in the
  // response, however anything could be returned including
  // a new web page or a redirect command

  socket_ptr->send_ptr = (byte *)HTTPStatus204;
  socket_ptr->send_len = STATUS_204_LEN;
}

< Previous Page

[ Introduction | Internet Connectivity Parameters | Case Study ]
[ Adapting the Software | Dynamic Web Pages | Feedback with Forms ]
[ Continuous Refresh | Security | Summary ]


Copyright © 2001 EE Times. All rights reserved.

ESAcademy, 2000

All materials
provided 'as is'
see Disclaimer

www.esacademy.com
info@esacademy.com