1.4.6. Processing HTML Data

Dealing with html files is often an error prone task. The helper class contains methods to generate the most common html sequences for anchors, forms and more.


  resp = getHeader("Index"); 1
  resp += makeCheckBox(makeIdent("method_enable_", i), 2
                       "on",
                       meth->isEnabled());
  resp += getTail(); 3

1

Create a standard html start sequence.

2

Append a check box with unique name and according value.

3

Append the standard html tail sequence.

When you process the form data you have to extract the according values. This may happen in the following manner:


  CppString handle_calc(const HtmlFormData &formdata,
                        CppString &mimetype)
  {
    mimetype = "text/html";

    if (   formdata.size() != 0
        && formdata.hasElement("lhs")  1
        && formdata.hasElement("rhs")
        && formdata.hasElement("operator")
       )
    {
      int l = getLong(formdata.getElement("lhs")[0]); 2
      int r = getLong(formdata.getElement("rhs")[0]);

      ...
    }

    return calc_response(); 3
  }

1

Check for existing and complete form data.

2

Extract the values and process them as required.

3

Generate the response based on the current data.