There are huge numbers of examples in the Moodle code that you could follow.
As you've given very little information about what code you have, it is very difficult to say what you are missing.
I assume you've managed to get the form to display, so you already have something like:
$form = new nameOfMyFormClass();
Have you tried to retrieve the data from the form?
if ($formdata = $form->get_data()) {
}
If so, then the data you want is in $formdata->fieldname1