Changes in the API with Drupal 5.7 ?

Matthieu - July 3, 2008 - 19:45

Hello,

I am working on a Drupal 5.7 installation. I use to work on the first version of Drupal 5 last year and developped some modules.

I get in trouble with the forms. I manage to make the form page but when I submit it, it doesn't perform the actions in the hook_form_submit hook and I get to a blank page. I am wondering if something changed since I worked on the form API or if I'm doing something wrong.

I have something looking like that in the hook_menu :

$items[] = array(
    'path' => 'addforumperso',
    'title' => t('Ajouter un Forum'),
    'callback' => 'drupal_get_form',
    'callback arguments' => 'forumspec_add_form',
    'access' => user_access('administer uieforum'),
    'type' => MENU_NORMAL_ITEM,
);

for the hook_form :

function forumspec_add_form() {
$form['ForumName'] = array(
  '#type' => 'textfield',
  '#title' => t('Sujet'),
  '#size' => 60,
  '#maxlength' => 128,
  '#required' => TRUE,
       );

$form['button'] = array(
  '#type' => 'submit',
  '#value' => t('Envoyer'),
  '#weight' => 19,
);

return $form;

for the hook_form_submit :

function forumspec_add_form_submit($form_id, $form_values) {
drupal_set_message(t('OK'));
db_query("INSERT INTO {f_forums} (ForumName, ForumDesc, Locked) VALUES (%s, %s, %d)", $form_values['ForumName'], $form_values['ForumDesc'], $form_values['Locked']);
}

Do you see anything looking bad ?

Thank you for your help.
Matthieu.

<?phpfunction

jamestamr - July 4, 2008 - 12:05

function forumspec_add_form($form_values = NULL) {
$form['ForumName'] = array(
  '#type' => 'textfield',
  '#title' => t('Sujet'),
  '#size' => 60,
  '#maxlength' => 128,
  '#required' => TRUE,
);

$form['button'] = array(
  '#type' => 'submit',
  '#value' => t('Envoyer'),
  '#weight' => 19,
);

return $form;

$form_values = NULL should be passed on to hook_form.

function forumspec_add_form_submit($form_id, $form_values) {
drupal_set_message(t('OK'));
db_query("INSERT INTO {f_forums} (ForumName, ForumDesc, Locked) VALUES ('%s', '%s', %d)", $form_values['ForumName'], $form_values['ForumDesc'], $form_values['Locked']);
}

%s should be with in ' ', eg '%s'.

James T
Action Medical Research - www.action.org.uk

 
 

Drupal is a registered trademark of Dries Buytaert.