You should consider using ad_form which greatly simplifies form creation and management.
Check out the docs for an example which demonstrates exactly what you want.