Form Building Error
I have copied over the code from step 1 in the form building video. The code looks like this:
input.module
<?php
// $Id$
/**
* @file
* Demonstrates use of the Form API.
*
- For a full list of elements and attributes, see:
- http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....
*/
/**
* Implements hook_menu().
*/
function input_menu()
{
$items['input/examples'] = array(
'title' => 'Form API examples',
'description' => 'Example of using the Form API.',
'page callback' => 'drupal_get_form',
'page arguments' => array('input_simple_form'),
'access callback' => TRUE,
);
return $items;
}
/**
* A simple form.
*/
function input_simple_form($form, &$form_submit)
{
$form['color'] = array(
'#title' => t('Favorite color'),
'#type' => 'textfield',
'#required' => TRUE,
'#description' => t('What is your favorite color? Blue? No, wait-'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
input.admin
<?php
// $Id$
/**
* @file
- Admin page callback for the scaffolding module.
*/
/**
* Builds and returns the scaffolding settings form.
*/
function input_admin_settings()
{
$form['input_example_setting'] = array(
'#type' => 'textarea',
'#title' => t('Example setting'),
'#default_value' => variable_get('input_example_setting' ''),
'#description' => t('This is an example setting.'),
'#required' => TRUE,
);
return system_settings_form($form);
}
input.info
; $Id:$
name = Beginning Forms
description = "A start on forms."
core = "6.x"
This throws the error:
warning: Missing argument 2 for input_simple_form() in C:\xampp\htdocs\drupal-6.22\sites\all\modules\input\input.module on line 51.
The only thing I can think of that I have done differently is that I am using drupal 6.22 rather than drupal 7. Is it possible that the code that takes care of the call expects 2 parameters in drupal 7, but only 1 parameter in drupal 6.22?
Instead of
You should write
<code>
Notice the comma between the first and second parameter in variable_get function call.
Hi there,
Good question, you're right about the issue being that you're using Drupal 6, which only takes one parameter for a form render array function. There were some changes to the Form API in Drupal 7 so applying the examples directly will not work properly. The general ideas are mostly the same, and the code is very similar, but you'll run into issues like you see above.
I hope that helps!
Chris