3

I am new to drupal, so basically i have made a simple registration form. The problem is when i go to the registration form it shows a blank page .

i have made 3 files by the name of my custom module -registerme i.e.-

1.registerme.info

name = Register Me  
description = A custom registration form    
package = Drupal 7 Development
core = 7.x
files[] = registerme.module

2.registerme.module

<?php

function registerme_menu()
{
$items['registerme/newform'] = array(
  'title' => 'Registration Form',
    'page callback' => 'drupal_get_form',
    'page arguments' => 'registerme_newform',
    'access callback' => TRUE,                    //array('access content'),
    'file' => 'registerme.newform.inc',
    'weight' => '-2',
 );
return $items;
}

3.And finally i have registerme.newform.inc

<?php
function registerme_newform(&$form_state) 
{
$form = array();
$form['account details'] = array(
    '#type' => 'fieldset',
    '#title' => t('Account Details')
);
$form['account details']['first name'] = array(
    '#type' => 'textfield',
    '#title' => t('First Name')
    );
$form['account details']['last name'] = array(
    '#type' => 'textfield',
    '#title' => t('Last Name')
    );
$form['account details']['mail'] = array(
    '#type' => 'textfield',
    '#title' => t('Last Name')
    );

$form['account details']['pass'] = array(
    '#type' => 'password',
    '#title' => t('Password'),
    '#maxlength' => 60,
    '#size' => 15,
    '#required' => TRUE,
    );
$form['account details']['pass'] = array(
    '#type' => 'password_confirm',
    '#description' => t('Enter the same password'),
    '#size' => 15,
    );
$form['home'] = array(
    '#type' => 'fieldset',
    '#title' => 'Home Address',
);
$form['home']['street'] = array(
    '#type' => 'textfield',
    '#title' => 'Street Address',
);
 $form['home']['city'] = array(
    '#type' => 'textfield',
    '#title' => 'City',
);
 $form['work'] = array(
    '#type' => 'fieldset',
    '#title' => 'Work Address',
);
$form['work']['street'] = array(
    '#type' => 'textfield',
    '#title' => 'Street Address',
);
 $form['work']['city'] = array(
    '#type' => 'textfield',
    '#title' => 'City',
);
 $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Register Me'),
 );
 return $form;
}
function registerme_newform_submit(&$form, &$form_state)
{
dsm($form_state);
} 
function registerme_newform_validate(&$form, &$form_state)
{
// Some validation to be done on fields.
}

where i am doing wrong getting errors like

Warning: Invalid argument supplied for foreach() in menu_unserialize() (line 400 of
    C:\webserver\Apache\htdocs\Starter\includes\menu.inc).        
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in
    menu_get_item() (line 479 of  
    C:\webserver\Apache\htdocs\Starter\includes\menu.inc).
Warning: call_user_func_array() expects parameter 2 to be array, null given in  
    menu_execute_active_handler() (line 516 of 
     C:\webserver\Apache\htdocs\Starter\includes\menu.inc).
Warning: Invalid argument supplied for foreach() in menu_unserialize() (line 400 of        
      C:\webserver\Apache\htdocs\Starter\includes\menu.inc).


The form dislpays a blank page when i click on the menu listing Register Me and the url is localhost/Starter/?q=registerme/newform

5

Error in hook_menu implementation ! See right code below.

function registerme_menu() {
  $items['registerme/newform'] = array(
    'title' => 'Registration Form',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('registerme_newform'), // Should be array !
    'access callback' => TRUE,                    //array('access content'),
    'file' => 'registerme.newform.inc',
    'weight' => '-2',
  );
  return $items;
}

function registerme_newform($form, &$form_state) {

}

function registerme_newform_submit($form, &$form_state)
{
  dsm($form_state);
} 
function registerme_newform_validate($form, &$form_state)
{
// Some validation to be done on fields.
}

Clear menu cache before checking !

| improve this answer | |
  • Thanks Anil just one small error is left. Warning: Parameter 1 to registerme_newform() expected to be a reference, value given in drupal_retrieve_form() (line 800 of C:\webserver\Apache\htdocs\Starter\includes\form.inc) Help me out. – Prerit Mohan Oct 8 '12 at 5:25
  • See the updated answer for change in signatures! – Anil Sagar Oct 8 '12 at 5:29
  • Hi, i know i am getting after your life but want to ask that can i use this registration form to register users and login accordingly with this form fields say name and password.Can this be acheived and how if possible .Just need guidance plz direct.I will br greatful to you.Thanks – Prerit Mohan Oct 8 '12 at 6:45
  • 1
    It's not recommend to re-invent the same wheel in Drupal. Drupal provides lot of out of the box solutions. If you want to add fields to user registration form check profile2 module !! – Anil Sagar Oct 8 '12 at 6:48

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.