Hey Guys,

I got a module error. Corrected it. There was a mistake while calling the function

Here is my code snippet:

INCORRECT VERSION
================

$items['tutumod/display'] = array(
'title' => 'display tutumod',
'description' => 'tutumodtutumodtutumodtutumodtutumodtutumodtutumodtutumod',
'page callback' => 'drupal_get_form',
'page arguments' => array('tutumod_nodeapi'),
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);

CORRECTED VERSION
================

$items['tutumod/display'] = array(
'title' => 'display tutumod',
'description' => 'tutumodtutumodtutumodtutumodtutumodtutumodtutumodtutumod',
'page callback' => 'tutumod_nodeapi',
// 'page arguments' => array('tutumod_nodeapi'),
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);

The problem was I already had an array element $items[...] that did this 'page callback' => 'drupal_get_form'.

So my question is:

Why did I get the error is it because I cant have 'page callback' => 'drupal_get_form' twice??? OR Is it cause if i have 'page callback' => 'drupal_get_form' I need to return an array that has the Form elements????

Comments

nevets’s picture

If page callback is drupal _get_form you to define page arguments with at least one argument, the form id of the form you want to display (by default the form id is the function name that builds the form).

Your form id though appears to be tutumod_nodeapi which is a hook function and would cause problems.

appraveen’s picture

Fatal error: Cannot unset string offsets in C:\wamp\www\drupal\includes\form.inc on line 485 was the error that I got Originally.

Nope. Thts not the case I changed the call back to my name still the same msg.

nevets’s picture

What does your function look like? It would useful if you posted the function plus your modules hook_menu function. Please remember to place the code between <code> and </code> tags.

appraveen’s picture

Here is the .module file. Please have a look and comment.

<?php

function memorycard_menu() {
  $items['memorycard/add'] = array(
    'title' => 'New Memory Card',
    'description' => 'Add new Memory Card',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('memorycard_get_form'),
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
  );
  $items['memorycard/display'] = array(
    'title' => 'Show Memory Cards',
    'description' => 'Show Memory Cards',
    'page callback' => 'praveen_here',
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}


function memorycard_get_form() {
  $form['key'] = array('#type' => 'textarea',
    '#title' => t('Key'),
    '#maxlength' => 100,
    '#description' => t("Provide the key"),
    '#required' => TRUE,
  );
  $form['value'] = array('#type' => 'textarea',
    '#title' => t('Value'),
    '#description' => t("Provide the value"),
    '#required' => TRUE,
  );
  $form['submit'] = array('#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}


function memorycard_get_form_submit($form, &$form_state){
	db_query("insert into {memory_card} (card_key, card_value) values ('%s','%s')",$form_state['values']['key'], $form_state['values']['value']);
	drupal_set_message(t("Memory Card Key and Value <b>Successfully Inserted</b>."));
}

function praveen_here(){

	$memorycard_content = '';

	$query = "SELECT * FROM {memory_card}";

	$query_result =  db_query($query);

	$memorycard_content .="<script type=\"text/javascript\" src=\"/drupal/sites/all/modules/tutumod/j.js\"></script>
	<script type=\"text/javascript\" src=\"/drupal/sites/all/modules/tutumod/c.js\"></script>
	<script type=\"text/javascript\">
	$(document).ready(function(){
	    $('#slideshow2').cycle({
		next:   '#next',
		speed: 800,
	        timeout: 0, 
		sync:0
    });
});
</script>";


	$memorycard_content .="<center>
	<div id=\"main\">
		<div id=\"demos\">
			<table cellspacing=\"2\">
				<tr>
					<td><a id=\"next\" href=\"#\">next</a></td>
			        <td><div id=\"title\"></div></td>
			    </tr>
				<tr>
				<td class=\"show\">
				    <div id=\"slideshow2\" style=\"font-size:23pt; letter-spacing:5px; line-height:100px; margin-bottom:300px; margin-top:100px; position:relative;\" >";

	while ($pair= db_fetch_object($query_result)) {
		$memorycard_content .= "<h1 style=\"font-family:Georgia; font-weight:bold;\">".$pair->card_key."</h1><h1 style=\"font-family:Georgia; font-weight:bold;\">".$pair->card_value.'</h1>';
	}

	$memorycard_content .="</div>
				</td>
			</tr>
		</table>
	</div></center>";

return $memorycard_content;
}