I ran into this as well and have learned the following: the loadFormData can indeed used to load previously saved data back into the form and Joomla does not seem to set the form data to the user state automatically. You have to do that somewhere.. with -indeed- setUserState.
The comment "// Check the session for previously entered form data." set me thinking and on a search for the how and why.
In my case I have 2 fields, from_date and to_date. In my com_myform\model\forms\myform.xml they are set to
<field name="from_date" type="calendar" [..] default="NOW" /> and
<field name="to_date" type="calendar" [..] default="NOW +1 week" /> so they are set to today and the same day next week.
In my form I wanted to keep the initial dates in case the (frontend) user entered some other value wrong. It should give an error message and fill the same form with the (previously) entered dates so the user could change other values without having to start over again.
In my helper function (com_myform\helper\processmyform.php) I do an availability check but before I continue I "save" the form data as below:
public function checkAvailability($fromDate, $toDate)
array('to_date' => $toDate, 'from_date' => $fromDate) );
As you can see I saved them in an array. Now in the loadFormData() I can easily access them! So in my com_myform\models\myform.php I do:
protected function loadFormData()
// Check the session for previously entered form data
$data = JFactory::getApplication()->getUserState(
And magically the data is inserted into the form. In this way you can populate form data with previously saved (and even changed) values.
Please note that you have to empty the UserState if you don't want to use the values over and over. After the (frontend) user dates were accepted and the form had to be set to the default dates, I would do a JFactory::getApplication()->setUserState(
I hope it helps someone!