I used hook_user_view_aler() to add some info to user's page.

 $account['summary']['member_five'] = array(
    '#type' => 'user_profile_item',
    '#title' => t('I do'),
    '#markup' => 'Real magic',

  $account['summary']['member_six'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => '',
    '#size' => 30,
    '#maxlength' => 60,
    '#required' => TRUE,

  $account['summary']['member_seven'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),

Also I added form elements and they do appear but I couldn't submit it. hook_user_view_aler_submit() obviously is too much and it doesn't work. Is there any way to create form on user's page?


You'll have to define a form function using the drupal form API See this tutorial for more info on how to make your own forms.

So the actual form function would look something like this

MY_FORM_FUNCTION($form, &$form_state){
  // Build form array here 
  return $form; 

MY_FORM_FUNCTION_validate($form, &$form_state){
  // Validate function here

MY_FORM_FUNCTION_submit($form, &$form_state){
  // Submit function here

Now in the tutorial they use HOOK_menu to display the form on a page. But you can call drupal_get_form('MY_FORM_FUNCTION') from everywhere and generate a render array for the form.

So this would show your form on the user page via HOOK_user_view_alter

 $account['form'] = drupal_get_form('MY_FORM_FUNCTION'); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.