Solved

Adding a form module to a specific page

Posted on 2010-09-24
2
522 Views
Last Modified: 2012-05-10
Ok, so I need to add a custom form to my user profile page in Drupal. I.e. the /user/1/edit/ form.
I don't want to just alter the existing form because I need it to have a different submission actions.
So I'm going to create a custom module for the form. This is an example I have found on the internet:

<?php

function example_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('This module implements an example form.');
  }
}

function example_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'example',
      'title' => t('Example'),
      'callback' => 'example_page',
      'access' => TRUE,
      'type' => MENU_CALLBACK
    );
  }
  return $items;
}

function example_page() {
  return drupal_get_form('example_page_form');
}

function example_page_form() {
  $form['fullname'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter your full name'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}

function example_page_form_submit($form_id, $form_values) {
  $message = 'You have submitted the ' . $form_id . ' form which contains the following data:<pre>' . print_r($form_values,true) . '</pre>';
  drupal_set_message(t($message));
}

?>

Open in new window


This is all well and good, but this just adds the form to the menu, and puts it on its own page. How could I get this form inserted into a particular area on my User Profile page?
I don't want to use the webforms module or anything, just want a custom form module inserted on my page.
Thanks,
0
Comment
Question by:liamrichards
2 Comments
 
LVL 17

Accepted Solution

by:
Thomas4019 earned 500 total points
ID: 33758616
Take a look at this. http://www.latenightpc.com/blog/archives/2009/02/13/overriding-the-edit-user-form-in-drupal-6

The built-in profile module does something similar to what you want. Maybe try reverse engineering it?
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Read about how to approach blogging and about ways to do it right. Stand out from the crowd and let your knowledge be consumed by a large audience. This article aims to explain how your blog should look like,  the most important things to do while b…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question