Understanding State

When you clicked on the button in the previous example, the HTML form posted its information back to itself. However, the state of the form was remembered from one webpage view to the next. Form objects, in fact, are stateful objects that maintain state from one post to the next. QCubed does this by serializing the entire form object, together with all its controls and subcontrols, into one long string and saving this information. This is known as formstate

. Before QCubed reads the information being submitted by the HTML form, it will unserialize the formstate to reconstruct the entire internal form structure, and then it will add the information being submitted from the HTML form.

In the example here, we have an $intCounter defined in the form. And basically, whenever you click on the button, we will increment $intCounter by one. Note that the HTML template file is displaying $intCounter directly via a standard PHP print statement.

Also note that session variables, cookies, etc. are not being used here -- only FormState. In fact, you can get an idea if you do View Source... in your browser of the HTML on this page. You will see a bunch of cryptic letters and numbers for the Qform__FormState hidden variable. Those letters and numbers actually represent the serialized version of this Form object.

By default, the form state is stored in a hidden form input. This may be fine for initial development of an application, but it is not secure, and has some performance and size limitations. Fortunately, QCubed provides you with a number of other mechanisms that let you store the formstate in PHP's session variable, in your database, or in an external cache. See the section on FormState Handlers for more information on how to configure those.

The current count is: 0