Hi There, Im just trying to use the form_alter hook, but not having much luck.
What Im trying to do is add a new option in the user settings page, to allow a user agreement to be specified...

At this stage, I have this code, but nothing will come up within the user settings admin page...

/**
 * Add the legal agreement in the user settings pages, for admin purposes.
 */
function gcs_form_alter($form_id, &$form)
{
  if ($form_id == 'user_admin_settings')
  {
    $form['registration']['user_agreement'] = array(
      '#type' => 'textarea', 
      '#title' => t('Legal Agreement'), 
      '#default_value' => t('testing'), 
      '#description' => t("This gives the user the option of agreening to this statement.")
    );
  }
}

Comments

Island Usurper’s picture

Hmm...that code looks like it should work. Make sure that the module that's contained in has been enabled. Next on the list is to check the form_id, make sure it's correct.

Other than that, it might be that the theme function for that form isn't rendering any parts of the form it didn't define. This would be a bug or require a very good explanation of why that is.

-----
Übercart -- One cart to rule them all.

Matthew OMalley’s picture

I agree that it looks good - if this is most of what you're doing with this module, you may want to take a look at http://drupal.org/project/legal.

______________________
Grand Junction Design, LLC
Web and Print Design For
Nonprofits and Foundations

usonian’s picture

I was having this same exact problem with user_admin_settings and form_alter(), and was tearing my hair out until I realized that I hadn't added

return $form;

to the end of my form_alter() hook. As soon as I did that it worked as expected.

Island Usurper’s picture

I suppose that's worth trying, but you really shouldn't have to. The $form array is passed by reference, so any changes made to it by this function are passed to the rest of FAPI.

-----
Übercart -- One cart to rule them all.

usonian’s picture

Thank you for pointing that out - I swear I tried adding the return statement after seeing it in another code snippet, and adding it did seem to work, but it doesn't seem right and perhaps I unknowingly fixed my code somewhere else.

-A

jbomb’s picture

So... "user_admin_settings" is the proper form_id for the form at :

http://www.example.com/?q=user/[uid]/edit

jbomb’s picture

You can modify the form at:

http://www.example.com/?q=user/[uid]/edit

using the following code:


function notify_user_form_alter($form_id, &$form) {
	if ($form_id == 'user_edit') {
	    // do something....
        }
}

halfiranian’s picture

Hi all,

Not sure if any of you can help, but I'm having a similar problem with form_alter. This doesn't seem to add the variable to the $form array, and I have no idea why. Any ideas much, much, appreciated:


function procon_form_alter($form_id, $form) {
  switch ($form_id) {
    case 'comment_form':

      $form['procon'] = array(
         '#type' => 'radios', 
         '#weight' => '10',
         '#title' => t('ProConAnti'), 
         '#options' => array( 
             t('Pro Argument'), 
             t('Con Argument'), 
             t('Neutral Comment')
          ), 
       );
	  return $form;
      break;
  }
}




Island Usurper’s picture

It should be

  function procon_form_alter($form_id, &$form) {

The & makes the $form pass by reference, so you don't have to return it. Whatever changes are done are passed back to the calling function.

And in general, you don't need "return" and "break" in the same place.

-----
Übercart -- One cart to rule them all.

halfiranian’s picture

Thanks so much mate, that really helped me out. J