Drupal 6 Forms API Screencast
This is a very introductory look at Forms API in Drupal 6.
The focus is on basic and practical application, and should allow the newest Drupal programmer to be able to go create his or her own form, in Drupal 6.
Attached is the code for your perusal--It's the same as what's demonstrated in the video, with a bunch of comments. (I would have attached a tarball, but it was not an acceptable file format)
The 30-minute screencast is hosted at blip.tv.
NOTE: In the video, I fail to use check_plain() when outputting some user-generated content...For the sake of you and your web site, don't forget this step. The attached code example is i believe doing it right
Corrections, Questions, Comments, and Smart Remarks are always welcome. :-)
| Attachment | Size |
|---|---|
| form_intro-module.txt | 3.97 KB |
| form_intro-info.txt | 270 bytes |


Thanks!
For those with slow computers, or if you want to save it and watch it later:
MPEG4 Video (.mp4):
http://blip.tv/file/get/Vordude-IntroToDrupal6FormsAPI891.MP4
Flash Video (.flv) :
http://blip.tv/file/get/Vordude-IntroToDrupal6FormsAPI891.flv
Thanks so much for putting the time into this!
Thanks for a great
Thanks for a great introduction.
I wish someone could update the Forms API Quickstart Guide too. I'm not sure how to do it since it's not a Wiki-page.
Thanks
Your screencast and code are very helpful.
Great tutorial
Hi,
Your screencast is logical, welll structured and VERY helpful....I have looked all over to come across this...indespensible....there is a real need for this level of drupal tutorial for the non-ninja developers!
Newbie Question
If I have already created my database fields in CCK. I have watched your tutorial & the API Forms tutorial, yet I still can not figure out how I indicate which textfield should update which database field?
Tami
You simply rock!!!!!
I've been going almost bald (from hair pulling) trying to understand the FAPI. This is by far the best introductory tutorial I have found and very very helpful.
Thanks for the great effort.
Jome.
yes this is superb
this really is good - even though everyone says drupal is easy to update - people need different methods of explanation to help them get started
more screencasts would be most welcome
many thanks
djax
Question: URL alias duplication issue from $items ['quiz']?
hi
this isnt a criticism - just a question - your tutorial is superb and i would be nowhere without it
i noticed you accessed the page where the form is displayed at www.example.com/quiz
and that the 'quiz' part of the url is created from the $items ['quiz'] array key below
function form_intro_menu () {
$items = array ();
$items ['quiz'] = array (
'title' => t('Super Cool Quiz'),
'page callback' => 'quiz_page' .............etc
thats great - but i then created a normal page and gave it the url alias of 'quiz' - thus creating a conflict (normally if you try to add a url alias that is already in use drupal flags this up and does not allow the page to be created)
the new 'quiz' page then overides the form 'quiz' page - and it is no longer possible to navigate to the form 'quiz' page
again - this isnt a criticism - i just noticed it when trying to figure out which page the form would display on - i wondered if there was a 'path_alias' key in hook_menu, so it could be set something like
function form_intro_menu () {
$items = array ();
$items ['quiz'] = array (
'title' => t('Super Cool Quiz'),
'page callback' => 'quiz_page',
'path_alias' => 'quiz', .............etc
but 'path_alias' or an equivalent does not seem to exist at http://api.drupal.org/api/function/hook_menu/6
do you have any ideas on this?
djax
One Question
First of all cool tutorial, extremely helpful. One problem I'm having is getting my form to submit. I'm writing an e-commerce page using ubercart. The form I created is supposed to add a product to cart. Here is what I have so far.
function custom_add_to_cart()
{
return drupal_get_form('uc_custom_cart');
}
function uc_custom_cart_form($form_state, $args)
{
$form = array();
$form['upgrade_option'] = array (
'#id' => 'upgrade_option_value',
'#type' => 'hidden',
'#default_value' => '-1',
);
$form['balloon_bouquet'] = array (
'#id' => 'balloon_bouquet_value',
'#type' => 'hidden',
'#default_value' => $args['bouquet_id'],
);
$form['additional_latex'] = array (
'#id' => 'additional_latex_value',
'#type' => 'hidden',
'#default_value' => '-1',
);
$form['additional_mylar'] = array (
'#id' => 'additional_mylar_value',
'#type' => 'hidden',
'#default_value' => '-1',
);
$form['add_teddy_bear'] = array (
'#id' => 'add_teddy_bear_value',
'#type' => 'hidden',
'#default_value' => '-1',
);
$form['submit'] = array (
'#type' => 'submit',
'#attributes' => array('class' => 'add_to_cart_btn'),
);
$form['#submit'][] = 'uc_custom_cart_form_submit';
return $form;
}
function uc_custom_cart_form_validate($form_id, &$form_state)
{
}
function uc_custom_cart_form_submit($form_id, &$form_state)
{
print("Form as been submitted");
//$form_state['redirect'] = "/";
}
I'm using the following to render the form, in my node-product.tpl.php file.
<?php$args = array('bouquet_id' => "$node->nid");
print drupal_get_form('uc_custom_cart_form', $args);
?>
Could anyone help or point in the right direction, I'm really stuck on this one.
Thanks