Solved

Adding a form module to a specific page

Posted on 2010-09-24
2
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

710 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