By sikko on
Hi,
I'm trying to override the contact form using this hook:
http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_form_FORM_ID_alter/7
So I created a module named contactfields:
sites/all/modules/contactfields/ has 2 files:
contactfields.info
; $Id:
name = Contact Fields
description = A simple module that adds fields to the contact form.
core = 7.x
package = Other
dependencies[] = "contact"
The form I want to alter is contact_site_form
contactfields.module
<?php
function hook_form_contact_site_form_alter(&$form, &$form_state, $form_id) {
// Modification for the form with the given form ID goes here. For example, if
// FORM_ID is "user_register_form" this code would run only on the user
// registration form.
// Add a checkbox to registration form about agreeing to terms of use.
$form['terms_of_use'] = array(
'#type' => 'checkbox',
'#title' => t("I agree with the website's terms and conditions."),
'#required' => TRUE,
);
}
?>It is absolutely not working.
Can you tell me what I'm doing wrong ?
Thank you in advance !
Comments
_
The word 'hook'-- should be replaced with your module's name.
Thank you for that quick and
Thank you for that quick and efficient reply.
Works like a charm (after emptying the cache).
(Drupal documentation could have been more clear this time...)
Thanks !
_
from http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/7:
There's a lot of docs that could use improvement, but I'm not really sure how it could be any clearer than that in this case.
It is very clear indeed. But
It is very clear indeed.
But the thing is when you access to the hook page directly (by a reference or by googling it), this information is missing.
I think they should have used [hook]_form_FORM_ID_alter like it's done most of times since brackets [] can't be in a function name.
Reason
If you look at
system.api.php, you can see a function called exactlyhook_form_FORM_ID_alter, which you can see here: hook_form_FORM_ID_alter().So these names refer to EXISTING function names and existing Drupal hooks, which modules can "use".
If you see a function which starts with
hook_, you can substitute the appropriate module name.You can read about Drupal hooks here:
Understanding the hook system for Drupal modules.