A beginners question regarding the quickest and easiet ways to implement simple forms in drupal.

I would like to have a form in a block that signs people up to a newsletter. All I want is their email address, either hit subscribe, unsubscribe and then submit, and have the values sent to a table in the database. I am not going to have any people creating user log-ins for this site (other than me as administrator), so this is the only way I am going to collect a list of people to mail to from my site.

Can anyone give me some basics on the best way to go about this? I am working on drupal version 5.x

many thanks,
Renaee.

Comments

lenkkivihko’s picture

this is a good place to start from: http://api.drupal.org/api/HEAD/file/developer/topics/forms_api.html

There seems to be quite many questions related to Form API. So this quick quide is not enought. Who knows a better newbie tutorial to Form API?

Renzy’s picture

Yes this is exactly what I need. I have had a read through the quickstart guide, but still not sure how to start. Some simple examples would be good.

This explanation gives me a guide:

   1. Your page-building function is called.
   2. It builds a form definition array.
   3. It calls drupal_get_form($form_id, $form), passing in a unique ID for the form and the form's definition array.
   4. drupal_get_form() first checks to see if there is incoming POST data. If there is, and the form_id in that POST data matches the $form_id you passed in, it knows that the user is submitting the form and begins the 'processing' stage.
         1. In the processing stage, drupal_get_form() passes the form array to drupal_validate_form(). Any validation handlers added to specific fields are processed there.
         2. If the validation stage completes and no errors are found, drupal_get_form() hands the form off to drupal_submit_form(). In that stage, data is processed, database changes are made, and so on.
         3. drupal_submit_form() can return a URL to redirect the user to when form processing is done. If it does, drupal_get_form() redirects to that page and the Form API is finished.
   5. If there is no incoming POST data. the processing stage returned validation errors, or no redirect URL was returned by drupal_submit_form(), the form array is passed to drupal_render_form() and the actual HTML is generated.
   6. Your page building function receives the generated HTML from drupal_get_form(), complete with hilighted errors if appropriate, and displays it to the user.
   7. If the user enters in values (either filling them in for the first time, or correcting errors) and clicks the Submit button, the form submits to itself, triggering the page building function in step 1... And the cycle repeats.

But it still does not cover the basics like is it the same page that both displays and procoesses the form, what do you put in for the form action and where are the values/variables stored, ie what table in the database?

An example of a fully coded form on a node or a block would be good?

If anyone knows where this is available from please let me know.

thanks,

choc full of drupally goodness...

movie-reviews.com.au