D7 Form Builder and Comment Forms
If you select the 'forms' tag and select its mini menu option 'info', you will see a link to the Drupal pages for the form API and a great basic explanation on how it is used.
You should not use PHP in the view. PHP in content of any sort presents a security risk. The best place to do this is in a custom module.
The form API provides documentation on both. 
$form_state is used as central storage for all information about the form. Any part of the $form_state array can be read and written to by any function at any time.