When a form is created, it is generally assigned an action which determines what happens when the form is submitted. If the action is left blank, then the form will call itself by default.
echo '<form action="" method="POST">'.
An alternative method is to use
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="POST">'.
however, this doesn't work when used within the context of a Joomla extension so use the first method.
The form is essentially broken up into to segments; the form segment and the processing segment. In order for the form script to determine which part of the script it is supposed to be acting on, you can check to see if $_POST['save'] has been set.
if(!isset($_POST['save'])) // form has not been submitted