Hi Carl, sorry I could not followup earlier. I also had to debug my code until I found how it had to work, there are not so many form_alter examples available. I try to help you, however I am not a real expert. And I hope that the thread is acceptable in drupal development. On 8/10/06, Carl Mc Dade <carl_mcdade@yahoo.com> wrote:
Well I have tried and tried to use form_alter in every way I could think of and in ways that others have but the code is just ignored or goes to error;
function profilecloud_form_alter($form_id, &$form) { $category = 'Medlemskonventet 2006'; if ($form_id == 'user_edit') { $alteration = array('#description' => t('ALTERED!!!!')); $form[$category]['edit-profile_matchmaking_2006'] = array_merge($form[$category]['edit-profile_matchmaking_2006'], $alteration); } }
I added material to the form as follows by adding one array element, in your case it would be: $form[$category]['edit-profile_matchmaking_2006'] = $alteration; In setting up $alteration you can use '#weight' => <number> to position your addition. Note that profile does not set weights, you may have to set weights alco for the other array elements to reach what you want. Not using weight means (I think) the PHP ordering prevails, which (I think) means first assigned array members are first.
produces a array merge error. $form[$category]['edit-profile_matchmaking_2006'] is not recognized as an array and forcing it returns no changes.
To get it to change this works. But the result is another complete form with a change within the original form.
function profilecloud_form_alter($form_id, &$form) { $category = 'Medlemskonventet 2006'; if ($form_id == 'user_edit') { $alteration = array('#description' => t('ALTERED!!!!')); $form[$category]['edit-profile_matchmaking_2006'] = array_merge($form[$category], $alteration); [...]
The code asks for what you observe... On 8/11/06, Carl Mc Dade <carl_mcdade@yahoo.com> wrote:
<?php function profilecloud_form_alter($form_id, &$form) { $category = 'Medlemskonventet 2006'; if ($form_id == 'user_edit') { $alteration = array('#description' => t('ALTERED!!!!'));
//$form[$category]['edit-profile_matchmaking_2006'] = array_merge($form[$category],$alteration); $form = array_merge($form[$category], $alteration);
} } ?>
Which produces results while nothing else in the docs or forum worked. The
$form[$category]['Medlemskonventet 2006'] = $alteration; should also have worked. The firs array_merge statement in your code is ineffectual I think.
problem is while it does add text to the form it does not alter it. The description stays the same and the added text appears at the top of the form. The second problem is that the extra text seems to exist in its own
In order to decide where your addition is rendered you need to use weights (see above).
array and stays at the top. Manipulating the array only moves the profile module fields and leaves the added text at the top. Everyone says use form _ alter but there is no documentation or examples of its use in the wild. The only way I have been able to get the exact results needed is to hardcode the profile module. Otherwise it does not seem possible. Is it?
It is indeed possible to alter profile forms with form_alter, the code snippet I sent previously works for me (Drupal 4.7.x). Greetings, -- Alberto