Solved

Adding a form module to a specific page

Posted on 2010-09-24
2
520 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

A Knowledge Base That Stays Up-to-Date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now